HDU5336 XYZ and Drops 暴力模拟
2015-08-01 11:24
459 查看
[align=left]Problem Description[/align]
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
[align=left]Input[/align]
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 following n
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 integers x,
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).
[align=left]Output[/align]
n
lines. Each line contains two integers Ai,
Bi:
If the i-th
waterdrop cracks in T
seconds, Ai=0,
Bi=
the time when it cracked.
If the i-th
waterdrop doesn't crack in T
seconds, Ai=1,
Bi=
its size after T
seconds.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
[align=left]Author[/align]
XJZX
[align=left]Source[/align]
2015 Multi-University Training Contest 4
题意:在一个r*c的棋盘上,有n个水坑,1<=r,c,n<=100。当一个水坑的size大于4只会,就会分裂成四个水滴,分别向四个不同的方向移动,并且水坑消失。当一个水滴进入到水坑时,水坑的size+1,水滴消失。初始的时候,在x,y点一个水坑分裂。问在T秒时各个水坑的状况。
思路:暴力模拟每秒每个水坑和水滴。
对于每一秒,移动每一个存在的水滴,当在棋盘外或者进入水坑时,该水滴消失,水坑size或者+1。再暴力枚举每个存在的水坑,检查其size,如果size>4,消失,产生四个不同方向水滴。
代码:
XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)[align=left]Problem Description[/align]
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
[align=left]Input[/align]
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 following n
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 integers x,
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).
[align=left]Output[/align]
n
lines. Each line contains two integers Ai,
Bi:
If the i-th
waterdrop cracks in T
seconds, Ai=0,
Bi=
the time when it cracked.
If the i-th
waterdrop doesn't crack in T
seconds, Ai=1,
Bi=
its size after T
seconds.
[align=left]Sample Input[/align]
4 4 5 10 2 1 4 2 3 3 2 4 4 3 1 2 4 3 4 4 4
[align=left]Sample Output[/align]
0 5 0 3 0 2 1 3 0 1
[align=left]Author[/align]
XJZX
[align=left]Source[/align]
2015 Multi-University Training Contest 4
题意:在一个r*c的棋盘上,有n个水坑,1<=r,c,n<=100。当一个水坑的size大于4只会,就会分裂成四个水滴,分别向四个不同的方向移动,并且水坑消失。当一个水滴进入到水坑时,水坑的size+1,水滴消失。初始的时候,在x,y点一个水坑分裂。问在T秒时各个水坑的状况。
思路:暴力模拟每秒每个水坑和水滴。
对于每一秒,移动每一个存在的水滴,当在棋盘外或者进入水坑时,该水滴消失,水坑size或者+1。再暴力枚举每个存在的水坑,检查其size,如果size>4,消失,产生四个不同方向水滴。
代码:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int Size[105][105]; const int dir[4][2] = { {1,0},{0,1},{-1,0},{0,-1} }; struct WATEDROP { int x, y; bool state; int T; WATEDROP() {} WATEDROP(int xx, int yy, int ss, int TT) { x = xx, y = yy, state = ss, T = TT; } }waterdrop[105]; struct DROP { int x, y; int d; bool state; DROP() {} DROP(int xx, int yy, int dd, int ss) { x = xx, y = yy, d = dd, state = ss; } }drop[500]; int drop_num; int n, m; inline bool in(int x, int y) { return 1 <= x&&x <= n && 1 <= y&&y <= m; } void init() { drop_num = 0; memset(Size, 0, sizeof(Size)); } int main() { int waterdrop_num, T; while (~scanf("%d %d %d %d", &n, &m, &waterdrop_num, &T)) { init(); for (int i = 1; i <= waterdrop_num; i++) { int x, y, s; scanf("%d %d %d", &x, &y, &s); waterdrop[i] = WATEDROP(x, y, 1, 0); Size[x][y] = s; } int sx, sy; scanf("%d %d", &sx, &sy); for (int i = 1; i <= 4; i++) drop[++drop_num] = DROP(sx, sy, i - 1, 1); for (int t = 1; t <= T; t++) { for (int i = 1; i <= drop_num; i++) { if (!drop[i].state) continue; drop[i].x += dir[drop[i].d][0]; drop[i].y += dir[drop[i].d][1]; if (!in(drop[i].x, drop[i].y)) { drop[i].state = 0; continue; } if (Size[drop[i].x][drop[i].y]) { Size[drop[i].x][drop[i].y]++; drop[i].state = 0; } } for (int i = 1; i <= waterdrop_num; i++) { if (!waterdrop[i].state) continue; if (Size[waterdrop[i].x][waterdrop[i].y] > 4) { waterdrop[i].state = 0; waterdrop[i].T = t; Size[waterdrop[i].x][waterdrop[i].y] = 0; for (int j = 0; j < 4; j++) drop[++drop_num] = DROP(waterdrop[i].x, waterdrop[i].y, j, 1); } } } for (int i = 1; i <= waterdrop_num; i++) { if (waterdrop[i].state) printf("1 %d\n", Size[waterdrop[i].x][waterdrop[i].y]); else printf("0 %d\n", waterdrop[i].T); } } return 0; }
相关文章推荐
- Win7升级成Win10后VMware安装CentOS不能联网的解决办法
- linux下安装交叉编译器
- Linux(Ubuntu发行版本)下的几种软件安装方式
- linux环境变量设置错误后,如何恢复解决方案:
- 模板维护-模板解析
- 模板维护-模板解析
- nginx的优化
- [翻译]用 Puppet 搭建易管理的服务器基础架构(3)
- Nginx fastcgi_param解释
- Rings'n'Ropes (Uva 10985 floyd+枚举)
- Linux下搭建/使用vsftpd服务器
- OpenCV——颜色均匀渐变
- linux初学(十九)之系统启动详解
- linux 遍历打印目录树
- hdu 1299 Diophantus of Alexandria
- linux服务器安装apache2和nodejs
- [日志分析]在nginx日志中,提取有效的request uri
- Hadoop权威指南(中文第2版)PDF
- 观CSDN网站小Bug有感
- Lucene六(IndexReader的设计)