hdu 5336 XYZ and Drops 模拟

来源:互联网 发布:淘宝需要3c认证怎么办 编辑:程序博客网 时间:2024/04/28 19:44

XYZ and Drops

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


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
 

Author
XJZX
 

Source
2015 Multi-University Training Contest 4
 

题意:水滴和小水滴是有区别的

小水滴不会合并,但是会被水滴吃掉。初始会给一个位置,水滴爆炸了。

如果一个水滴的大小>4水滴会爆掉,产生4个小水滴,向四个方向移动,

问一个水滴如果爆掉,什么时间爆的。如果没爆掉,输出水滴最后的大小。


分析:小水滴最多4n个,直接模型小水滴的移动,如果遇到水滴,则合并,再判断合并后的水滴是否爆炸。


解题报告提到如果r,c,n <= 100000,T <= 10^9的时候怎么处理

这时考虑用十字链表构建整个水滴网络,最多有4n个小水滴,每个小水滴最多被合并一次。

对于每个水滴,爆炸的时候能够立刻算出小水滴与一下个水滴合并的时间。用一个数据

结构维护合并时间最小的事件,然后模拟即可。


#include<iostream>#include<cstring>#include<cstdio>#include<vector>using namespace std;int map[101][101];struct Point{    int x,y,xu,yu;    Point(){}    Point fu(int dx,int dy){        Point a;        a.x = x, a.y = y, a.xu = dx, a.yu = dy;        return a;    }};vector<Point> baozha;vector<Point> shuidi;vector<Point> ans;vector<Point> les;int dir[4][2] = {0,1,1,0,-1,0,0,-1};int main(){    int r,c,n,t;    while(scanf("%d%d%d%d",&r,&c,&n,&t)!=EOF){        memset(map,0,sizeof(map));        baozha.clear();        shuidi.clear();        ans.clear();        Point a,b;        int u;        for(int i = 0;i < n; i++){            scanf("%d%d%d",&a.x,&a.y,&u);            map[a.x][a.y] = u;            ans.push_back(a);        }        scanf("%d%d",&a.x,&a.y);        for(int i = 0;i < 4; i++)            baozha.push_back(a.fu(dir[i][0],dir[i][1]));        for(int tt = 1; tt <= t; tt++){            if(baozha.size() == 0) break;            les.clear();            shuidi.clear();            for(int i = 0;i < baozha.size(); i++){                a = baozha[i];                a.x += a.xu, a.y += a.yu;                if(a.x <= 0 || a.x > r || a.y <= 0 || a.y > c) continue;                if(map[a.x][a.y] > 0){                    map[a.x][a.y]++;                    if(map[a.x][a.y] > 4)                        shuidi.push_back(a);                }                else les.push_back(a);            }            baozha.clear();            for(int i = 0;i < shuidi.size(); i++){                a = shuidi[i];                if(map[a.x][a.y] <=0) continue;                for(int j = 0; j < 4; j++)                    baozha.push_back(a.fu(dir[j][0],dir[j][1]));                map[a.x][a.y] = -tt;            }            for(int i = 0;i < les.size();i++)                baozha.push_back(les[i]);        }        for(int i = 0;i < n; i++){            a = ans[i];            if(map[a.x][a.y] > 0 ){                printf("1 %d\n",map[a.x][a.y]);            }            else printf("0 %d\n",-map[a.x][a.y]);        }    }    return 0;}




0 0
原创粉丝点击