Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
【大模拟】终于ac了,干干干!!!#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct node { int kind,x,y,can; }a[8]; int x,y,n,tu[12][12]; int mx[4]={0,0,1,-1}; int my[4]={1,-1,0,0}; bool in(int x,int y) { if(x<=0||y<=0||x>10||y>9) return 0; return 1; } bool check(int aim_x,int aim_y) { for(int i=1;i<=n;i++) if(a[i].can) { int x=a[i].x,y=a[i].y; // printf("%d %d %d\n",a[i].kind,x,y); switch(a[i].kind) { case 1: { if(aim_y!=y) break; int wr=0; for(int i=aim_x+1;i<x;i++) { // printf("%d %") if(tu[i][y]) wr=1; } if(wr) break; // printf("1:\n"); return 0; } case 2: { for(int i=0;i<4;i++) { int tx=x+mx[i]; int ty=y+my[i]; while(in(tx,ty)&&tu[tx][ty]==0) { // printf("2:%d %d\n",tx,ty); if(tx==aim_x&&ty==aim_y) return 0; tx+=mx[i]; ty+=my[i]; } } break; } case 3: { for(int i=0;i<4;i++) { int tx=x+mx[i]; int ty=y+my[i]; while(in(tx,ty)&&tu[tx][ty]==0) { tx+=mx[i]; ty+=my[i]; } if(tu[tx][ty]) { tx+=mx[i]; ty+=my[i]; while(in(tx,ty)&&tu[tx][ty]==0) { // printf("3: %d %d\n",tx,ty); if(tx==aim_x&&ty==aim_y) return 0; tx+=mx[i]; ty+=my[i]; } } } break; } case 4: { for(int i=0;i<4;i++) { int tx=x+mx[i]; int ty=y+my[i]; if(!in(tx,ty)||tu[tx][ty]) continue; int ux=abs(mx[i])^1; int uy=abs(my[i])^1; int nx=tx+mx[i]+ux; int ny=ty+my[i]+uy; // printf("4: %d %d\n",nx,ny); if(nx==aim_x&&ny==aim_y) return 0; nx-=ux<<1; ny-=uy<<1; // printf("4: %d %d\n",nx,ny); if(nx==aim_x&&ny==aim_y) return 0; } break; } } } return 1; } int main() { // freopen("in.txt","r",stdin); while(scanf("%d%d%d",&n,&x,&y),!(n==0&&x==0&&y==0)) { memset(tu,0,sizeof(tu)); for(int i=1;i<=n;i++) { char s[10]; scanf("%s%d%d",s,&a[i].x,&a[i].y); a[i].can=1; if(s[0]=='G') a[i].kind=1; else if(s[0]=='R')a[i].kind=2; else if(s[0]=='C') a[i].kind=3; else a[i].kind=4; tu[a[i].x][a[i].y]=i; } bool ans=1; if(check(x,y)) ans=0; for(int i=0;i<4;i++) { int nx=x+mx[i]; int ny=y+my[i]; //f(!in(nx,ny)) continue; if(ny<4||ny>6||nx<1||nx>3) continue; // printf("***%d %d***\n",nx,ny); int mark=tu[nx][ny]; tu[nx][ny]=0; a[mark].can=0; if(check(nx,ny)) {ans=0;break;} a[mark].can=1; tu[nx][ny]=mark; } printf("%s\n",ans?"YES":"NO"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator