- Time: 2016-04-17-16:20:49 Sunday
- Title Number: [2016-04-17][gym][100947][b][queens, again!!]
- Title: 8 Queen question, give 8 Queen's position, judge whether 8 queen can attack each other
- Analysis:
- Peer, same column, same diagonal
- Same diagonal: The difference of the horizontal ordinate, and the same
- Problems encountered:
#include<cstdio>
using namespace std;
struct Point{
int x,y;
}p[10];
int check(int a,int b){
if ( p [ a x == p [ b . x return Span class= "lit" >1
if ( p [ a y == p [ b . y return Span class= "lit" >1
if ( p [ a x - p [ a . y == p [ b . x - p [ b . y return Span class= "lit" >1
if ( p [ a x + p [ a . y == p [ b . x + p [ b . y return Span class= "lit" >1
return 0;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
char str[10];
for(int i = 0 ; i < 8 ; ++i){
scanf("%s",str);
p[i].x = str[0] - ‘A‘;
p[i].y = str[1] - ‘0‘;
}
int flg = 1;
for ( int i = 0 ; FLG && I < 8 ; ++ i ) {
for ( int J = I + 1 Span class= "pun"; FLG && J < 8 ; ++ j ) {
if(check(i,j)){
flg = 0;
}
}
}
puts(flg ? "Valid" : "Invalid");
}
return 0;
}
From for notes (Wiz)
[2016-04-17] [Gym] [100947] B [Queens, again!!]