HDU5336 XYZ and Drops 暴力模拟



XYZ and Drops

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


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 ( 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?

1r100 , 1c100 , 1n100 , 1T10000
 

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 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 . ( 1sizei4 )
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).
 

Output
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.
 

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 3 0 1
 

Author
XJZX
 

Source

题意:在一个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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值