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<<"
    ";
    		}
    	}
    }
    
  • 相关阅读:
    数据库优化空间换时间优化
    sql server性能分析查询死锁和阻塞的sql语句
    修改储存过程所有者
    SQL Server 查看数据库基本信息
    SQL语句之普通行列转换
    Ext.Window
    小议操作符“^”与"&"的应用
    数据库设计名值模式(转)
    为数据库建立索引
    sql server性能分析检测数据库阻塞语句
  • 原文地址:https://www.cnblogs.com/liangyj/p/14195186.html
Copyright © 2011-2022 走看看