# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13379 | 2015-02-14T13:39:36 Z | baneling100 | Ants (IZhO12_ants) | C++ | 0 ms | 1220 KB |
#include <stdio.h> #include <algorithm> #include <vector> #define W_MAX 100 #define H_MAX 100 #define K_MAX 100 using namespace std; struct ant { int X; int D; int Num; bool operator < (ant P) const {return X<P.X;} }; struct res { int X; int Y; int D; } Ans[K_MAX+1]; vector <ant> Want[H_MAX], Hant[W_MAX]; int W, H, K, Tw, Th, Dx[5]={0,1,0,-1,0}, Dy[5]={0,0,1,0,-1}; int main(void) { int i, j, k, s, T, X, Y, D; ant temp; scanf("%d %d %d %d",&W,&H,&K,&T); Tw=T%(W<<1), Th=T%(H<<1); for(i=1 ; i<=K ; i++) { scanf("%d %d %d",&X,&Y,&D); D%2 ? Want[Y].push_back({X,D,i}) : Hant[X].push_back({Y,D,i}); } for(i=1 ; i<H ; i++) { s=Want[i].size(); if(s) { sort(Want[i].begin(),Want[i].end()); for(j=1 ; j<=Tw ; j++) { for(k=0 ; k<s ; k++) Want[i][k].X+=Dx[Want[i][k].D]; for(k=1 ; k<s ; k++) { if(Want[i][k-1].X>=Want[i][k].X) { temp=Want[i][k-1]; Want[i][k-1]=Want[i][k]; Want[i][k]=temp; X=Want[i][k-1].Num; Want[i][k-1].Num=Want[i][k].Num; Want[i][k].Num=X; } } if(Want[i][0 ].X==0) Want[i][0 ].D=(Want[i][0 ].D+1)%4+1; if(Want[i][s-1].X==W) Want[i][s-1].D=(Want[i][s-1].D+1)%4+1; } for(j=0 ; j<s ; j++) Ans[Want[i][j].Num]={Want[i][j].X,i,Want[i][j].D}; } } for(i=1 ; i<W ; i++) { s=Hant[i].size(); if(s) { sort(Hant[i].begin(),Hant[i].end()); for(j=1 ; j<=Th ; j++) { for(k=0 ; k<s ; k++) Hant[i][k].X+=Dy[Hant[i][k].D]; for(k=1 ; k<s ; k++) { if(Hant[i][k-1].X>=Hant[i][k].X) { temp=Hant[i][k-1]; Hant[i][k-1]=Hant[i][k]; Hant[i][k]=temp; X=Hant[i][k-1].Num; Hant[i][k-1].Num=Hant[i][k].Num; Hant[i][k].Num=X; } } if(Hant[i][0 ].X==0) Hant[i][0 ].D=(Hant[i][0 ].D+1)%4+1; if(Hant[i][s-1].X==H) Hant[i][s-1].D=(Hant[i][s-1].D+1)%4+1; } for(j=0 ; j<s ; j++) Ans[Hant[i][j].Num]={i,Hant[i][j].X,Hant[i][j].D}; } } for(i=1 ; i<=K ; i++) printf("%d %d %d\n",Ans[i]); return 0; }