2015ACM多校对抗赛第四场 hdu 5336

来源:互联网 发布:node实战 编辑:程序博客网 时间:2024/04/30 02:03

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5336

XYZ and Drops

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1024    Accepted Submission(s): 291


Problem Description
XYZ is playing an interesting game called "drops". It is played on a rc 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 (xy), before the first second there is a waterdrop cracking at position (xy). XYZ wants to know each waterdrop's status after T seconds, can you help him?

1r1001c1001n1001T10000
 

Input
The first line contains four integers rcn and Tn stands for the numbers of waterdrops at the beginning. 
Each line of the following n lines contains three integers xiyisizei, meaning that the i-th waterdrop is at position (xiyi) and its size is sizei. (1sizei4)
The next line contains two integers xy

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 integers AiBi
If the i-th waterdrop cracks in T seconds, Ai=0Bi= the time when it cracked. 
If the i-th waterdrop doesn't crack in T seconds, Ai=1Bi= its size after T seconds.
 

Sample Input
4 4 5 102 1 42 3 32 4 43 1 24 3 44 4
 

Sample Output
0 50 30 21 30 1
 

题意:十滴水游戏的改版。
现在某个位置有一滴即将爆炸的水滴,爆炸后,将产生四个方向的四个小水滴,每一秒只能移动一步,这些小水滴要么出了表格边界,要么和其他水滴融合,被吸收。
当融合后的值达到5的时候,又会发生爆炸,问给定n个起始水滴的T时刻后的状态。0表示爆炸了+爆炸时刻。1表示没有爆炸+最后时刻水滴大小。

宽搜就行了,用优先队列维护,并标记。

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<queue>using namespace std;#define sf scanfconst int d[4][2]={1,0,0,1,-1,0,0,-1};struct node{    int t,x,y,d;    bool operator<(const node &a)const{return t>a.t;}};struct point{    int x,y;}a[105];int r,c,n,T;priority_queue<node> que;int mapt[102][102];int ans[101][101];bool legel(int x,int y){return x>0&&x<=r&&y>0&&y<=c;}void addque(node p){    for(int i = 0;i<4;i++)        {            int xx = p.x + d[i][0];            int yy = p.y + d[i][1];            while(legel(xx,yy)&&mapt[xx][yy] == 0) {xx+=d[i][0];yy+=d[i][1];}            //cout<<xx<<" "<<yy<<endl;            if(mapt[xx][yy] != 0)                    {                        //cout<<xx<<","<<yy<<":"<<abs(xx+yy-p.x-p.y)+p.t<<endl;                        que.push(node{abs(xx+yy-p.x-p.y)+p.t,xx,yy,i});                    }        }}int main(){    while(~sf("%d%d%d%d",&r,&c,&n,&T))    {        memset(mapt,0,sizeof mapt);        memset(ans,0,sizeof ans);        for(int i = 0;i<n;i++)        {            int x,y,z;            sf("%d%d%d",&x,&y,&z);            mapt[x][y] = z;            a[i] = point{x,y};        }        int x,y;        sf("%d%d",&x,&y);        while(!que.empty()) que.pop();        addque(node{0,x,y,0});        while(!que.empty())        {            node p = que.top();            //cout<<p.t<<":"<<p.x<<","<<p.y<<"----------"<<endl;            que.pop();            if(p.t>T) continue;            if(mapt[p.x][p.y]<=4)            {                mapt[p.x][p.y]++;                if(mapt[p.x][p.y]==5)                {                    addque(p);                    ans[p.x][p.y] = p.t;                }            }            else            {                if(ans[p.x][p.y] != p.t)                {                    int xx = p.x + d[p.d][0];                    int yy = p.y + d[p.d][1];                    while(legel(xx,yy)&&mapt[xx][yy] == 0) {xx+=d[p.d][0];yy+=d[p.d][1];}                    if(mapt[xx][yy] != 0)                    {                      //  cout<<xx<<","<<yy<<":"<<abs(xx+yy-p.x-p.y)+p.t<<endl;                        que.push(node{abs(xx+yy-p.x-p.y)+p.t,xx,yy,p.d});                    }                }            }        }        for(int i =0;i<n;i++)            if(ans[a[i].x][a[i].y]!=0)                printf("0 %d\n",ans[a[i].x][a[i].y]);            else                printf("1 %d\n",mapt[a[i].x][a[i].y]);    }    return 0;}




0 0