Problem Description
XYZ is playing an interesting game called "drops". It is played on ar∗c grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right). In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won't collide. Then for each cell occupied by a waterdrop, the waterdrop's size increases by the number of the small drops in this cell, and these small drops disappears. You are given a game and a position (x ,y ), before the first second there is a waterdrop cracking at position (x ,y ). XYZ wants to know each waterdrop's status afterT seconds, can you help him?1≤r≤100 ,1≤c≤100 ,1≤n≤100 ,1≤T≤10000
Input
The first line contains four integersr ,c ,n andT .n stands for the numbers of waterdrops at the beginning. Each line of the followingn lines contains three integersxi ,yi ,sizei , meaning that thei -th waterdrop is at position (xi ,yi ) and its size issizei . (1≤sizei≤4 ) The next line contains two integersx ,y . It is guaranteed that all the positions in the input are distinct. Multiple test cases (about 100 cases), please read until EOF (End Of File).
Output
n lines. Each line contains two integersAi ,Bi : If thei -th waterdrop cracks inT seconds,Ai=0 ,Bi= the time when it cracked. If thei -th waterdrop doesn't crack inT seconds,Ai=1 ,Bi= its size afterT seconds.
Sample Input
4 4 5 10 2 1 4 2 3 3 2 4 4 3 1 2 4 3 4 4 4
Sample Output
0 5 0 3 0 2 1 30 1
来个优先级队列记录一下时间,暴力的搞吧
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<stack> #include<map> #include<algorithm> #include<string> #pragma comment(linker, "/STACK:102400000,102400000") typedef long long ll; using namespace std; const ll maxn=105; int T,n,m,t,f[maxn][maxn],x,y,a[maxn],b[maxn],c[maxn][maxn]; struct point { int x,y,z,t,now; point(){} point(int x,int y,int z,int t,int now): x(x),y(y),z(z),t(t),now(now) {}; bool operator <(const point &a) const { return now+t>a.now+a.t; } }; int get(int x,int y,int d) { if (d&1) { if (d==1) { for (int i=y+1;i<=m;i++) if (f[x][i]) return i-y; return 0; } else { for (int i=y-1;i>=1;i--) if (f[x][i]) return y-i; return 0; } } else { if (d==0) { for (int i=x-1;i>=1;i--) if (f[i][y]) return x-i; return 0; } else { for (int i=x+1;i<=n;i++) if (f[i][y]) return i-x; return 0; } } } int main() { //scanf("%d",&T); while (~scanf("%d%d%d%d",&n,&m,&t,&T)) { memset(f,0,sizeof(f)); memset(c,0,sizeof(c)); for (int i=1;i<=t;i++) { scanf("%d%d",&x,&y); a[i]=x; b[i]=y; scanf("%d",&f[x][y]); } scanf("%d%d",&x,&y); priority_queue<point> p; for (int i=0;i<4;i++) { int k=get(x,y,i); if (k>0) p.push(point(x,y,i,k,0)); } while (!p.empty()) { point tp,q=p.top(); p.pop(); for (;;p.pop()) { if (p.empty()) break; tp=p.top(); if(tp.now+tp.t!=q.now+q.t) break; int k=get(tp.x,tp.y,tp.z); if (!k) continue; if (k!=tp.t) p.push(point(tp.x,tp.y,tp.z,k,tp.now)); else { if (k+tp.now>T) break; if (tp.z==0) x=tp.x-k,y=tp.y; if (tp.z==1) x=tp.x,y=tp.y+k; if (tp.z==2) x=tp.x+k,y=tp.y; if (tp.z==3) x=tp.x,y=tp.y-k; f[x][y]++; } } int k=get(q.x,q.y,q.z); if (k) if (k!=q.t) p.push(point(q.x,q.y,q.z,k,q.now)); else { if (k+q.now>T) break; if (q.z==0) x=q.x-k,y=q.y; if (q.z==1) x=q.x,y=q.y+k; if (q.z==2) x=q.x+k,y=q.y; if (q.z==3) x=q.x,y=q.y-k; f[x][y]++; } for(int i=1;i<=t;i++) { x=a[i]; y=b[i]; if (f[x][y]>4) { f[x][y]=0; c[x][y]=q.t+q.now; for (int j=0;j<4;j++) { int u=get(x,y,j); if (u>0) p.push(point(x,y,j,u,q.t+q.now)); } } } } for (int i=1;i<=t;i++) { if (f[a[i]][b[i]]) printf("1 %d\n",f[a[i]][b[i]]); else printf("0 %d\n",c[a[i]][b[i]]); } } return 0; }