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 r∗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 after T seconds, can you help him?
1≤r≤100 , 1≤c≤100 , 1≤n≤100 , 1≤T≤10000
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 (
Input
The first line contains four integers r , c , n and T . n stands for the numbers of waterdrops at the beginning.
Each line of the followingn lines contains three integers xi , yi , sizei , meaning that the i -th waterdrop is at position (xi , yi ) and its size is sizei . (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).
Each line of the following
The next line contains two integers
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
If the
If the
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
- hdu 5336 XYZ and Drops 【BFS模拟】
- hdu 5336 XYZ and Drops 模拟
- hdu 5336 XYZ and Drops(模拟)
- HDU 5336 XYZ and Drops (BFS模拟)
- HDU-5336 XYZ and Drops 模拟十滴水
- Hdu 5336 XYZ and Drops(模拟)
- HDU 5336 XYZ and Drops
- HDU 5336 XYZ and Drops
- hdu 5336 XYZ and Drops
- hdu 5336 XYZ and Drops
- HDU 5336 XYZ and Drops
- Hdu 5336 XYZ and Drops
- HDU 5336 XYZ and Drops
- HDU 5336 XYZ and Drops(十滴水游戏) 模拟
- HDU 5336 XYZ and Drops (模拟+搜索,详解)
- HDU 5336 - XYZ and Drops(暴力模拟)
- hdu 5336 XYZ and Drops(模拟十滴水游戏bfs)
- 模拟,bfs(HDU 5336,XYZ and Drops)
- JavaScript
- 《实现领域驱动设计》系列(1) DDD入门
- java的反射性能测试
- sqlServer存储过程的加密和解密方法
- 模2运算的原理
- hdu 5336 XYZ and Drops 模拟
- 快速排序--小结
- OAuth2.0 原理
- android 键值(input)
- 设计单片机硬件系统应遵循的原则
- 什么品牌的独轮车最好
- 蓝牙 相关知识
- Roman to Integer
- 添加动作