第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)B Mine Sweeper II

题目

A mine-sweeper map {X}X can be expressed as an n\times mn×m grid. Each cell of the grid is either a mine cell or a non-mine cell. A mine cell has no number on it. Each non-mine cell has a number representing the number of mine cells around it. (A cell is around another cell if they share at least one common point. Thus, every cell that is not on the boundary has 8 cells around it.) The following is a 16\times 3016×30 mine-sweeper map where a flagged cell denotes a mine cell and a blank cell denotes a non-mine cell with number 0.

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

题意

给你两张n*m的图,如果图中的格子不是雷的话,就代表着周围8个格子雷的数量,改变下面图不超过\((m*n)/2\)向下取整个格子(雷变成数字,或者数字变成雷) 使得下面的数字的和等于上面的图

思路

统计一下两图的差别,如果超过\((m*n)/2\)就把上面的图反转,否则就改变下面的图所有不同的即可,因为图是互补的时候,数字也是相等的。

代码

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000+100;

char mp1[maxn][maxn],mp2[maxn][maxn];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	cin>>mp1[i][j];
	
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	cin>>mp2[i][j];
	
	int sum = 0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		if(mp1[i][j] != mp2[i][j])
		sum++;
	}
	int cnt = (m*n)/2;
	
	if(sum > cnt)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(mp1[i][j] == '.')
				cout<<'X';
				else
				cout<<".";
			}
			cout<<"\n";
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			cout<<mp1[i][j];
			cout<<"\n";
		}
	}
}
posted @ 2020-12-27 01:01  墨墨墨小白iiy💭💡🎈  阅读(176)  评论(0编辑  收藏  举报