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 |
放代码,这题有点麻烦= =#include<iostream> #include<cstdio> #include<string> #include<vector> #include<algorithm> #include<map> using namespace std; int dirx[]={1,0,-1,0}; int diry[]={0,1,0,-1};// right,up,left,down int shoot; int now; int N,M; typedef struct tank { int x,y; bool run; bool die; int dir; string name; }Tank; map <string,int> find_tank; typedef struct command { int time; string name; string act; }command; typedef struct bullet { int x,y; int dir; bool die; }Bullet; bool In(int x,int y) { if(x>=0&&x<=72&&y>=0&&y<=72) return true; else return false; } Tank tank[15]; command ins[1000]; Bullet bullet[301]; void RunAll() { for(int i=1;i<=N;++i) { if(!tank[i].die&&tank[i].run) { if(In(tank[i].x+dirx[tank[i].dir],tank[i].y+diry[tank[i].dir])) { tank[i].x+=dirx[tank[i].dir]; tank[i].y+=diry[tank[i].dir]; } else tank[i].run=false; } } for(int i=1;i<=shoot;++i) { if(!bullet[i].die) { if(In(bullet[i].x+dirx[bullet[i].dir]*2,bullet[i].y+diry[bullet[i].dir]*2)) { bullet[i].x+=dirx[bullet[i].dir]*2; bullet[i].y+=diry[bullet[i].dir]*2; } else bullet[i].die=true; } } for(int i=1;i<=N;++i) { if(tank[i].die) continue; for(int j=1;j<=shoot;++j) { if(bullet[j].die) continue; if(tank[i].x==bullet[j].x&&tank[i].y==bullet[j].y) { tank[i].die=true; bullet[j].die=true; } } } } int main() { while(scanf("%d%d",&N,&M)&&(N|M)) { shoot=0; now=0; for(int i=1;i<=N;++i) { cin>>tank[i].name>>tank[i].x>>tank[i].y>>tank[i].dir; tank[i].x=tank[i].x*6/10; tank[i].y=tank[i].y*6/10; tank[i].dir/=90; tank[i].die=false; tank[i].run=false; find_tank[tank[i].name]=i; } for(int i=1;i<=M;++i) { cin>>ins[i].time>>ins[i].name>>ins[i].act; ins[i].time*=6; while(ins[i].time>now) { RunAll(); now++; } if(ins[i].act=="MOVE") tank[find_tank[ins[i].name]].run=true; else if(ins[i].act=="STOP") tank[find_tank[ins[i].name]].run=false; else if(ins[i].act=="SHOOT") { if(!tank[find_tank[ins[i].name]].die) { shoot++; bullet[shoot].die=false; bullet[shoot].x=tank[find_tank[ins[i].name]].x; bullet[shoot].y=tank[find_tank[ins[i].name]].y; bullet[shoot].dir=tank[find_tank[ins[i].name]].dir; } } else { int angle; cin>>angle; angle/=90; tank[find_tank[ins[i].name]].dir=(angle+tank[find_tank[ins[i].name]].dir+4)%4; } } for(int i=1;i<=15*6;++i) RunAll(); int cnt=0; for(int i=1;i<=N;++i) { if(!tank[i].die) cnt++; } if(cnt!=1) cout<<"NO WINNER!\n"; else { for(int i=1;i<=N;++i) if(!tank[i].die) cout<<tank[i].name<<endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator