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

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

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

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

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. How to create jar for Android Library Project

    http://stackoverflow.com/questions/17063826/how-to-create-jar-for-android-library-project This works ...

  2. UIGestureRecongnizer 手势拦截

    在一个scrollview添加了一个tap的手势事件,然后在scrollview上添加了几个Button,在ios6,ios7 中两个点击事件相安无事,但在ios5中按钮却无法点击,究其原因是因为在i ...

  3. silverlight 控件自定义样式 实现方法

    1:在app.xaml中加入需实现的样式,如: <Application.Resources> <Style x:Key="NodeStyle" TargetTy ...

  4. 使用Putty连接VirtualBox的Ubuntu

    从vbox中安装了ubuntu server,然后用ssh连过去,发现有一个错误:server unexpectedly closed network connection.猛然发现,ssh没有安装. ...

  5. iOS开发网络编程之断点续传-NSURLConnection

    最近在做一个小项目的时候,发现使用NSURLSession或者AFNNetworking进行断点续传时诸多的不便,于是自己封装了一个类来实现断点续传,在程序重新启动时仍然可以继续下载(需自己调用方法) ...

  6. Stateless Iterators

    As the name implies, a stateless iterator is an iterator that does not keep any state by itself. The ...

  7. hdoj 2112 HDU Today

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=2112 分析:多了一个地方的条件,用map来映射地点编号,Dijkstra求解即可 //2013-10- ...

  8. poj 2253 Frogger (最短路变种,连通图的最长边)

    题目 这里的dijsktra的变种代码是我看着自己打的,终于把代码和做法思路联系上了,也就是理解了算法——看来手跟着画一遍真的有助于理解. #define _CRT_SECURE_NO_WARNING ...

  9. Java程序员学C#基本语法两个小时搞定(对比学习)

    对于学习一门新的语言,关键是学习新语言和以前掌握的语言的区别,但是也不要让以前语言的东西,固定了自己的思维模式,多看一下新的语言的编程思想. 1.引包 using System;java用import ...

  10. asp.net-(含:模拟登陆,照片列表)

    一.画好用户登录界面 同时换下请求的地址. 获取用户信息及判断代码插入位置: 一.画好用户登录界面 同时换下请求的地址. 获取用户信息及判断代码插入位置: <%@ WebHandler Lang ...