HDU 5336 XYZ and Drops

这道题目最主要是题意好迷,我老是get不到那个点。

题意为:一个r*c的方格有n个水滴,然后我们指定一个起点,他会向四周发射一粒小水滴,这个水滴只会在到达原本有水滴的方格才会停止(或者离开方格范围),并且使该处的水滴数+1。如果某个地方这一秒的水滴数大于4,则又会分裂为四个方向的小水滴。各个水滴之间不会碰撞。

我首先肯定是想到bfs,然后自行操作一下。。。

等我明白题意后,改了改就好了。。。当然有坑点,discuss上有。


代码如下:

#include<bits/stdc++.h>
using namespace std;
int dir[][2] = {0,1,0,-1,1,0,-1,0};
int r, c, n, T;
map <int, int>Map;
int G[105][105];

struct node
{
	int x, y, cnt, director;
	node(){}
	node(int a, int b, int c)
	{
		x = a;
		y = b;
		cnt = c;
	}
}ans[105];

bool Check(node t)
{
	if(t.x > 0 && t.x <= r && t.y > 0 && t.y <= c && t.cnt <= T)
		return 1;
	return 0;
}

queue <node> q;

void add_point(node now, int i)
{
	node next;
	next.x = now.x + dir[i][0];
	next.y = now.y + dir[i][1];
	next.cnt = now.cnt + 1;
	next.director = i;
	if(Check(next))
		q.push(next);
}

void bfs(int sx, int sy)
{
	vector<pair<int, int> >v;
	int tmp = 0;
	node now;
	now = node(sx, sy, 0);
	for(int i = 0; i < 4; i++)
		add_point(now, i);
	while(!q.empty())
	{
		now = q.front();
		q.pop();
		if(now.cnt != tmp)
		{
			for(int i = 0; i < v.size(); i++)
				G[v[i].first][v[i].second] = 0;
			tmp = now.cnt;
			v.clear();
		}
		if(G[now.x][now.y] > 0)
		{
			G[now.x][now.y]++;
			if(G[now.x][now.y] == 5)
			{
				v.push_back(make_pair(now.x, now.y));
				for(int j = 0; j < 4; j++)
					add_point(now, j);
				int key = Map[now.x * 1000 + now.y];
				ans[key].cnt = now.cnt;
			}
		}
		else
			add_point(now, now.director);
	}
}

int main()
{
	int x, y, val;
	while(cin >> r >> c >> n >> T)
	{
		memset(G, 0, sizeof(G));
		Map.clear();
		for(int i = 0; i < n; i++)
		{
			scanf("%d%d%d", &x, &y, &val);
			ans[i].x = x;
			ans[i].y = y;
			ans[i].cnt = -1;
			Map[1000 * x + y] = i;
			G[x][y] = val;
		}
		scanf("%d%d", &x, &y);
		bfs(x, y);
		for(int i = 0; i < n; i++)
		{
			if(ans[i].cnt >= 0)
				printf("0 %d\n", ans[i].cnt);
			else
				printf("1 %d\n", G[ans[i].x][ans[i].y]);
		}
	}
	return 0;
} 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值