A-Plague Inc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A-Plague Inc相关的知识,希望对你有一定的参考价值。

???????????????   abap   mem   ret   selected   repeat   lang   using   ted   

A-Plague Inc

 

?????????n*m?????????????????????????????????????????????????????????????????????????????????????????????????????????4???????????????????????????????????????????????????????????????????????????x?????????????????????x?????????????????????y???????????????

??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????wa????????????

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 10;
int vis[maxn][maxn];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n, m;
	while (scanf("%d%d", &n, &m) != EOF)
	{
		int num;
		pair<int, int>ans;
		memset(vis, 0, sizeof vis);
		scanf("%d", &num);
		queue<pair<int, int> > q;
		ll sum = num;
		for (int i = 0; i < num; i++)
		{
			int x, y;
			scanf("%d%d", &x, &y);
			q.push(make_pair(x, y));
			vis[x][y] = 1;
		}
                //?????????????????????????????????
		while (sum < n * m)
		{
			int tmp = q.size();
                        //????????????????????????????????????4???????????????????????????
			for (int i = 0; i < tmp; i++)
			{    
				if (q.front().second + 1 <= m && !vis[q.front().first][q.front().second + 1])
				{
					q.push(make_pair(q.front().first, q.front().second + 1));
					vis[q.front().first][q.front().second + 1] = 1;
					sum++;
				}
				if (q.front().second - 1 > 0 && !vis[q.front().first][q.front().second - 1])
				{
					q.push(make_pair(q.front().first, q.front().second - 1));
					vis[q.front().first][q.front().second - 1] = 1;
					sum++;
				}
				if (q.front().first + 1 <= n && !vis[q.front().first + 1][q.front().second])
				{
					q.push(make_pair(q.front().first + 1, q.front().second));
					vis[q.front().first + 1][q.front().second] = 1;
					sum++;
				}
				if (q.front().first - 1 > 0 && !vis[q.front().first - 1][q.front().second])
				{
					q.push(make_pair(q.front().first - 1, q.front().second));
					vis[q.front().first - 1][q.front().second] = 1;
					sum++;
				}
				q.pop();//????????????
			}
		}
		ans = q.front();
                //??????????????????????????????????????????????????????
		while (!q.empty())
		{

			if (ans.first > q.front().first)
				ans = q.front();
			else if (ans.first == q.front().first && q.front().second < ans.second)
				ans = q.front();
			q.pop();
		}
		printf("%d %d
", ans.first, ans.second);
	}
	return 0;
}
??????????????????

以上是关于A-Plague Inc的主要内容,如果未能解决你的问题,请参考以下文章

分享几个实用的代码片段(附代码例子)

调用模板化成员函数:帮助我理解另一个 *** 帖子中的代码片段

OpenGL - glDrawElementsInstanced - 片段着色器和不正确的颜色

What's new in C# 7.0

What's new in C# 7.0

Dreamweaver CS4 Mac 中的颜色代码 .inc