zoukankan      html  css  js  c++  java
  • 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)B Mine Sweeper II

    题目

    A mine-sweeper map {X}X can be expressed as an n imes 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 imes 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<<"
    ";
    		}
    	}
    	else
    	{
    		for(int i=1;i<=n;i++)
    		{
    			for(int j=1;j<=m;j++)
    			cout<<mp1[i][j];
    			cout<<"
    ";
    		}
    	}
    }
    
  • 相关阅读:
    写给所有的IT民工们
    如何不重启系统加载.SYS文件
    六十八个经典故事
    利用C#重启远程计算机
    无为无不为
    男人心里到底藏着哪些秘密?
    Microsoft好员工的十个标准
    javascript版的日期输入控件
    书写NDIS过滤钩子驱动实现ip包过滤
    男人25岁前的忠告#必阅
  • 原文地址:https://www.cnblogs.com/liangyj/p/14195186.html
Copyright © 2011-2022 走看看