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

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

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

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

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. 微软职位内部推荐-SDE2 (Windows - Power)

    微软近期Open的职位: SDE2 (Windows - Power) Windows Partner Enablement team in Operating System Group is loo ...

  2. 仿微博视频边下边播之滑动TableView自动播放-b

    Tips:这次的内容分为两篇文章讲述01.[iOS]仿微博视频边下边播之封装播放器 讲述如何封装一个实现了边下边播并且缓存的视频播放器.02.[iOS]仿微博视频边下边播之滑动TableView自动播 ...

  3. SOLID architecture principles using simple C# examples

    转:http://www.codeproject.com/Articles/703634/SOLID-architecture-principles-using-simple-Csharp?msg=4 ...

  4. memcached+memadmin

    一.安装apache yum install httpd 二.安装php yum install php* 三.apache配置 vi /etc/httpd/conf/httpd.conf 添加Add ...

  5. 精通ASP.Net MVC 3 框架(第三版)学习笔记

    精通ASP.Net MVC 3 框架(第三版)学习笔记 代码才是王道. http://pan.baidu.com/s/1pJyL1cn

  6. 15个实用的jQuery技术

    JQuery是目前最流行的JavaScript框架之一,可以显著的提高用户与网络应用的交互. 今天为大家介绍50有用的jQuery技术: 1.移动Box 2.滑动框和标题 3.数据的可视化:使用HTM ...

  7. Unity3D开发(五):Unity3D 4.x 使用Mecanim实现连击(转)

    原地址:http://www.unitymanual.com/blog-1801-1221.html unity3d 4.x 版本之后提供了一种新的动画机制Mecanim,虽然目前还支持之前的Anim ...

  8. Pycharm

    1.下载pycharm-community-3.0.2.exe 2.setting: keymap scheme:快捷键方案,可选择自带的:default:或者选择eclipse的快捷方案. ide ...

  9. ZOJ 3261 Connections in Galaxy War(逆向并查集)

    参考链接: http://www.cppblog.com/yuan1028/archive/2011/02/13/139990.html http://blog.csdn.net/roney_win/ ...

  10. C#的cs文件中Response.Clear();Response.ClearHeaders()的作用

    在学习一个CS文件,如下:public partial class GetPic : System.Web.UI.Page{    protected void Page_Load(object se ...