码迷,mamicode.com
首页 > 其他好文 > 详细

解题报告 之 HDU5336 XYZ and Drops

时间:2015-08-28 13:33:52      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:多校   acm   模拟   hdu5336   

解题报告 之 HDU5336 XYZ and Drops


Description

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

技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享 
 

Input

The first line contains four integers 技术分享技术分享技术分享 and 技术分享技术分享 stands for the numbers of waterdrops at the beginning. 
Each line of the following 技术分享 lines contains three integers 技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享, meaning that the 技术分享-th waterdrop is at position (技术分享技术分享技术分享技术分享) and its size is 技术分享技术分享技术分享技术分享技术分享. (技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享
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

技术分享 lines. Each line contains two integers 技术分享技术分享技术分享技术分享
If the 技术分享-th waterdrop cracks in 技术分享 seconds, 技术分享技术分享技术分享技术分享技术分享技术分享技术分享 the time when it cracked. 
If the 技术分享-th waterdrop doesn‘t crack in 技术分享 seconds, 技术分享技术分享技术分享技术分享技术分享技术分享技术分享 its size after 技术分享 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

题目大意:有一个n*m的网格,有k个水洼,给出k个水洼的坐标和水量([1,4])。一个水洼水量超过四就立即会向上下左右各发射一个水滴并立即消失,水滴每秒移动一个格子,遇到新的水洼就加入进去,出了边缘就消失。现在在0s时有一个水洼在(x,y)爆裂,问 T 秒后原来那些水洼的信息(爆裂/未爆裂等等)。

分析:一道毫无节操的模拟题,直接模拟每个水滴和水洼就可以了。。。本来还想着优化一下把爆裂的水洼去掉,后来发现太麻烦了就直接上了,结果还是A掉了。每过一秒更新每个水滴和水洼的状态,注意先水滴后水洼,因为水洼可能爆裂产生水滴那么下一秒这些水滴就要移动了。有一个巧妙的点是,判断一个水洼是不是已经消失了用二维数组Size来判断而不是去扫描一遍。

上代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
const int MAXN = 100 + 10;

struct wp
{
	int x, y;
	int state;
	int t;
	wp()
	{

	}
	wp( int x, int y, int state, int t )
	{
		this->x = x;
		this->y = y;
		this->state = state;
		this->t = t;
	}
};

struct drop
{
	int x, y;
	int dir;
	int state;
	drop()
	{ }
	drop( int x, int y, int dir,int state )
	{
		this->x = x;
		this->y = y;
		this->dir = dir;
		this->state = state;
	}
};

int dir[4][2] = { {-1,0},{1,0},{0,-1},{0,1} };
wp p[MAXN];
drop d[MAXN * 10];
int Size[MAXN][MAXN];
int n, m, k, t;

bool inline check( int x, int y )
{
	return 1 <= x&&x <= n && 1 <= y&&y <= m;
}

int main()
{
	while(scanf( "%d%d%d%d", &n, &m, &k, &t ) == 4)
	{
		int x, y, s;
		memset( Size, 0, sizeof Size );
		for(int i = 0; i < k; i++)
		{
			scanf( "%d%d%d", &x, &y, &s );
			Size[x][y] = s;
			p[i] = wp( x, y, 1, -1 );
		}

		scanf( "%d%d", &x, &y );
		int cnt = 0;
		for(int i = 0; i < 4; i++)
		{
			d[cnt++] = drop( x, y, i, 1 );
		}
		
		for(int tt = 1; tt <= t; tt++)
		{
			for(int i = 0; i < cnt; i++)
			{
				if(d[i].state == 0) continue;
				d[i].x += dir[d[i].dir][0];
				d[i].y += dir[d[i].dir][1];
				if(!check( d[i].x, d[i].y ))
				{
					d[i].state = 0;
				}

				if(Size[d[i].x][d[i].y]>0)
				{
					Size[d[i].x][d[i].y]++;
					d[i].state = 0;
				}
			}

			for(int i = 0; i < k; i++)
			{
				if(p[i].state == 0)continue;
				if(Size[p[i].x][p[i].y]>4)
				{
					p[i].state = 0;
					p[i].t = tt;
					Size[p[i].x][p[i].y] = 0;
					for(int j = 0; j < 4; j++)
					{
						d[cnt++] = drop( p[i].x, p[i].y, j, 1 );
					}
				}
			}
		}
		
		for(int i = 0; i < k; i++)
		{
			printf( "%d %d\n", p[i].state, (p[i].state == 0 ? p[i].t : Size[p[i].x][p[i].y]) );
		}
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

解题报告 之 HDU5336 XYZ and Drops

标签:多校   acm   模拟   hdu5336   

原文地址:http://blog.csdn.net/maxichu/article/details/48029219

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!