Codeforces Round #212 (Div. 2) A. Two Semiknights Meet /B. Petya and Staircases
来源:互联网 发布:matlab导入多个txt数据 编辑:程序博客网 时间:2024/04/29 10:53
A题:A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
题解:这就是英文理解题了。。。在8*8的格子里面有两个K,他们只能向上走2次并且左或者右两次,或者向下走两次并且左或者右两次,'#'表示不可走。问这两个K都要走,能不能相遇,能则输出‘YES’。
我们只用考虑这两个k的坐标关系就可以了。假设两个K的x坐标x1,x2相差为2或者1,那么怎么走x坐标都没法相等。推导相差4或者4的倍数就可以了。
A题:
#include<cstdlib>#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;int main(){ int T,x1,x2,y1,y2; char c; cin>>T; while(T--) { bool flag = false; for(int i=0;i<8;i++) for(int j=0;j<8;j++) { cin>>c; if(c=='K') { if(!flag) { x1=i; y1=j; flag= true; } else { x2=i,y2=j; } } } if(abs(x1-x2)%4==0&&abs(y1-y2)%4==0) cout<<"YES"<<endl; else cout<<"NO"<<endl; }}
B题:理解题意就可以做了。这个人跳台阶,第一个台阶和最后一个台阶都不能是脏的,并且连续3个台阶是脏的也GAME OVER。。
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<algorithm>using namespace std;int a[3003];int n,m;int main(){ while(cin>>n>>m) { bool ans= false ; for(int i=1;i<=m;i++) { cin>>a[i]; } sort(a+1,a+1+m); if(a[1]==1||a[m]==n) { cout<<"NO"<<endl; continue; } int tmp=a[1]; int cnt=0; for(int i=2;i<=m;i++) { if(a[i]-tmp==1) { cnt++; tmp=a[i]; } else if(a[i]-tmp>1) { cnt=0; tmp=a[i]; } if(cnt>=2) { ans=true; break; } } if(ans) cout<<"NO"<<endl; else cout<<"YES"<<endl; }}
- Codeforces Round #212 (Div. 2) A. Two Semiknights Meet /B. Petya and Staircases
- Codeforces Round #212 (Div. 2) A A. Two Semiknights Meet
- Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
- Codeforces Round #212 (Div. 2) B. Petya and Staircases
- Codeforces Round #212 (Div. 2) B. Petya and Staircases
- Codeforces 362A Two Semiknights Meet
- CodeForces 362A - Two Semiknights Meet
- Two Semiknights Meet CodeForces
- Two Semiknights Meet CodeForces
- A. Two Semiknights Meet
- A - Two Semiknights Meet
- Codeforces 362B Petya and Staircases
- CodeForces 362B Petya and Staircases
- CodeForces 362B Petya and Staircases
- Codeforces 362B. Petya and Staircases
- Codeforces Round #425 (Div. 2)B. Petya and Exam
- Codeforces Round #425 (Div. 2) B. Petya and Exam
- Codeforces Round #425 (Div. 2) B. Petya and Exam
- eclipse运行程序时出现问题:(工程名上命名的红叉)
- 人工智能(AI)概述
- 子串和
- Codeforces 362A Two Semiknights Meet
- linux c socket之开源http服务器tinyhttpd
- Codeforces Round #212 (Div. 2) A. Two Semiknights Meet /B. Petya and Staircases
- 【java源码】对mysql数据库的封装(精华版)
- libtool
- 3.2 Defining Horizontal and Vertical Constraints with the Visual Format Language
- SQL SERVER 事务执行情况跟踪分析
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
- 谈谈对于企业级系统架构的理解
- Java正则表达式用法
- 我的Android进阶之旅------>android api的源代码下载地址