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;
}
}