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

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

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

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

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. 微软职位内部推荐-Senior Software Development En

    微软近期Open的职位: Job Title: Senior Development Engineer Division: Visual Studio China - Developer Divisi ...

  2. C# Double toString保留小数点方法

    有时候double型数据需要toString(),但又想保留小数,当值为整数,比如3.00时tostring后会变为”3″,具体说明见下: 1 string str0 = i.ToString(&qu ...

  3. mysql存储过程出现OUT or INOUT argument 10 for routine

    OUT or INOUT argument 10 for routine * is not a variable or NEW pseudo-variable 我查网上很多出现在call的时候没有添加 ...

  4. C#的配置文件App.config使用总结 - 转

    http://blog.csdn.net/celte/article/details/9749389 首先,先说明,我使用的app.config 配置文件的格式如下: <?xml version ...

  5. c++ 时间格式化

    struct tm tm_time; strptime(time.c_str(), "%Y%m%d %H:%M:%S", &tm_time); time_t tt = mk ...

  6. 【转载】C++中结构体的声明和定义

    http://blog.csdn.net/whuslei/article/details/5665289 1  //定义一个结构体,类型为struct Student 2  struct  Stude ...

  7. MVC4 错误: 检测到有潜在危险的 Request.Form值

    说明: 请求验证过程检测到有潜在危险的客户端输入值,对请求的处理已经中止.该值可能指示存在危及应用程序安全的尝试,如跨站点脚本攻击.若要允许页面重写应用程序请求验证设置,请将 httpRuntime  ...

  8. memmove和memcpy 以及strcmp strcpy几个库函数的实现

    memmove和memcpy 1.memmove 函数原型:void *memmove(void *dest, const void *source, size_t count) 返回值说明:返回指向 ...

  9. hdu 2196

    树形dp 本文出自   http://blog.csdn.net/shuangde800 题目传送门 题意: 给出一棵树,求离每个节点最远的点的距离 思路: 把无根树转化成有根树分析, 对于上面那棵树 ...

  10. javax.mail.MessagingException: 501 Syntax: HELO hostname Linux端异常解决

    在项目里面使用javamail在window环境正常,放在服务器上面的时候抛出异常javax.mail.MessagingException: 501 Syntax: HELO hostname ,原 ...