网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
2
4 2
R 1 1
B 1 5
Output
YES
Input
2
4 2
R 3 3
B 1 5
Output
NO
Note
Picture for the first sample:

White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "
YES".
Picture for the second sample:

Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "
NO".
题目大意,给你一个白色的王,问在同一水平同一垂直上是否有黑车或者黑皇后(不能有其他棋子挡住)
在同一对角线上是否有黑象或者黑皇后(不能有其他棋子挡住)
思路
直接找白王周边的棋子,取各个方向最近的棋子,判断这些棋子是否满足上文说的下棋方向。
膜拜一位大佬写的简单代码,自己在他的基础上稍改动一点,看上去很清爽
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int dir(point now){
if(now.xxx&&now.y<yy) return 0;
if(now.xxx&&now.y>yy) return 1;
if(now.x<xx&&now.y==yy) return 2;
if(now.x>xx&&now.y==yy) return 3;
if(xx+yy==now.x+now.y&&now.y<yy) return 4;
if(xx+yy==now.x+now.y&&now.y>yy) return 5;
if(xx-yy==now.x-now.y&&now.y<yy) return 6;
if(xx-yy==now.x-now.y&&now.y>yy) return 7;
return -1;
}
int dis(point a){
return max(abs(a.x-xx),abs(a.y-yy));
}
void update(point &old,point now){
if(old.kind==‘?’||dis(now)<dis(old))
{
old=now;
}
}
int main()
{
int n;
scanf(“%d%d%d”,&n,&xx,&yy);
for(int i=0;i<8;i++)
{
rounds[i].kind='?';
}
for(int i=0;i<n;i++){
point now;
getchar();
scanf("%c%d%d",&now.kind,&now.x,&now.y);
int dire=dir(now);
if(dire>=0){
update(rounds[dire],now);
}
}
bool flag=false;
for(int i=0;i<8;i++){
if(i<4&&rounds[i].kind=='R'||rounds[i].kind=='Q')
{
flag=true;
break;
}
if(i>=4&&rounds[i].kind=='B'||rounds[i].kind=='Q')
{
flag=true;
break;
}
}
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
提升。**
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!