做了一道题,对了,但是还是掉分了。

第二道题也做了,但是没有交上,不知道对错。

后来交上以后发现少判断了一个条件,改过之后就对了。

第一道题爆搜的,有点麻烦了,其实几行代码就行。

250贴代码:

 #include <iostream>
#include <cstring>
#include <queue>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std; class BishopMove
{
public:
struct node
{
int x, y, step;
} next, pos;
int howManyMoves(int r1, int c1, int r2, int c2)
{
int vis[][], i, a, b;
memset(vis, , sizeof(vis));
if(r1==r2 && c1==c2)
return ; queue<node>q;
vis[r1][c1] = ;
next.x = r1;
next.y = c1;
next.step = ;
q.push(next);
while(!q.empty())
{
pos = q.front();
if(pos.x == r2 && pos.y == c2)
return pos.step; q.pop();
for(i = ; i <= ; i ++)
{
a = pos.x+i;
b = pos.y+i;
if(a>=&&a<= && b>= && b<= && vis[a][b]==)
{
vis[a][b] = ;
next.x = a;
next.y = b;
next.step = pos.step+;
q.push(next);
}
a = pos.x+i;
b = pos.y-i;
if(a>=&&a<= && b>= && b<= && vis[a][b]==)
{
vis[a][b] = ;
next.x = a;
next.y = b;
next.step = pos.step+;
q.push(next);
}
a = pos.x-i;
b = pos.y+i;
if(a>=&&a<= && b>= && b<= && vis[a][b]==)
{
vis[a][b] = ;
next.x = a;
next.y = b;
next.step = pos.step+;
q.push(next);
}
a = pos.x-i;
b = pos.y-i;
if(a>=&&a<= && b>= && b<= && vis[a][b]==)
{
vis[a][b] = ;
next.x = a;
next.y = b;
next.step = pos.step+;
q.push(next);
}
}
}
return -;
}
}; int main()
{
int r1, c1, r2, c2;
while()
{
cin>>r1>>c1>>r2>>c2;
BishopMove y;
cout<<y.howManyMoves(r1, c1, r2, c2)<<endl;
}
return ;
}

题意:有三种括号 和 x,x能变成任意的括号,求能否通过变化x使得给的字符串符合括号匹配

500贴代码:

AC代码:

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <vector>
#define LL long long
using namespace std; class BracketExpressions
{
public:
int _max(int c, int d)
{
return c > d?c:d;
}
int match(char a, char b)
{
if(a=='(' && b==')')
return ;
if(a=='{' && b=='}')
return ;
if(a=='[' && b==']')
return ;
if(a=='X' &&(b==']'||b=='}'||b==')'))
return ;
if(b=='X' && (a=='['||a=='{'||a=='('))
return ;
if(a=='X' && b=='X')
return ;
return ;
}
string ifPossible(string expression)
{
int i, j, k, g, len;
int d[][];
string s = expression;
len = s.size();
memset(d, , sizeof(d));
for(i = ; i < len-; i++)
if(match(s[i], s[i+]))
d[i][i+] = ;
for(k = ; k < len; k++)
{
for(i = ; i < len-k; i++)
{
j = i+k;
if(match(s[i], s[j])) d[i][j] = d[i+][j-] + ;
for(g = ; g < k; g++)
d[i][j] = _max(d[i][i+g]+d[i+g+][j], d[i][j]);
}
}
if(*d[][len-]!=len)
return "impossible";
else
return "possible";
}
};

topcoder srm 628 div2 250 500的更多相关文章

  1. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

  2. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

  3. topcoder srm 610 div2 250

    第一次做tc 的比赛,一点也不懂,虽然题目做出来了, 但是,也没有在比赛的时候提交成功.. 还有,感谢一宁对tc使用的讲解.. 贴一下代码..... #include <cstring> ...

  4. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  5. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  6. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  7. Topcoder SRM 619 DIv2 500 --又是耻辱的一题

    这题明明是一个简单的类似约瑟夫环的问题,但是由于细节问题迟迟不能得到正确结果,结果比赛完几分钟才改对..耻辱. 代码: #include <iostream> #include <c ...

  8. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  9. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

随机推荐

  1. Android journey 1@关于编码风格和命名规范

    /* * 1.关于编程风格:每一位程序猿可能都有自己独特的编程风格,但是有些规则是大家都必须遵守的,特别 * 是在工作的过程中,良好的代码风格能大大提高代码本身的可阅读性和维护性,也更有利于别人修改你 ...

  2. 关于sublime text的配置方法

    一个星期没有写博客了, 是时候来一波了 -------------------------------------------------------------------------------- ...

  3. Codeforces Round #360 (Div. 2) E. The Values You Can Make 01背包

    题目链接: 题目 E. The Values You Can Make time limit per test:2 seconds memory limit per test:256 megabyte ...

  4. MongoDB { code: 18, ok: 0.0, errmsg: "auth fails" } 原因

    MongoDB出现 { code: 18, ok: 0.0, errmsg: "auth fails" }  错误的原因: 1.账号密码错误 2.账号不属于该数据库

  5. HTTP请求报文与响应报文

    http://docs.telerik.com/fiddler/KnowledgeBase/HTTP HTTP请求报文与响应报文 HTTP http://www.w3.org/Protocols/rf ...

  6. ECMALL目录结构设置与数据库表

    [Ecmall]ECMALL目录结构设置与数据库表   最近在做ecmall的开发,ecmall在开源方面还有待进步啊,官方没有提供开发文档,也没有关于系统架构组织的贡献,使用者都要自己从0开始,官方 ...

  7. DevOps 和技术债务偿还自动化

    当企业想要迁移到一个 DevOps 模型时,经常需要偿还高等级的技术债务 说得更明确一点,机构往往陷入「技术债务的恶性循环」中,以至于任何迅速.敏捷的迁移方式都无法使用.这是技术债务中的希腊债务危机水 ...

  8. 终于明白公测的beta 源自何处了

    A very early version of a software product that may not contain all of the features that are planned ...

  9. Android 近百个项目的源代码

    Android 近百个项目的源代码 Android PDF 阅读器 http://sourceforge.net/projects/andpdf/files/个人记账工具 OnMyMeans http ...

  10. hdu2013

    http://acm.hdu.edu.cn/showproblem.php?pid=2013 #include<iostream> #include<stdio.h> #inc ...