多校第十场——1003 Mine Sweeper

Problem Description
A mine-sweeper map can be expressed as an r×c grid, and each cell of the grid is either mine cell or non-mine cell. A mine cell has no number on it, while a non-mine cell has a number, the number of mine cells that share at least one common point with the cell, on it. Following is a 16×30 mine-sweeper map, where flag cells denotes mine cells while blank cells denotes non-mine cells with number 0 on them.

在这里插入图片描述

Given an integer S, construct a mine-sweeper map of r,c both not exceeding 25, whose sum of numbers on non-mine cells exactly equals S. If multiple solutions exist, print any one of them. If no solution, print “-1” in one line.

Input
The first line contains one positive integer T (1≤T≤1001), denoting the number of test cases. For each test case:

Input one line containing one integer S(0≤S≤1000).

Output
For each test case:

If no solution, print “-1” in one line.

If any solution exists, print two integers r,c(1≤r,c≤25) in the first line, denoting the size of the mine-sweeper map. Following r lines each contains a string only containing “.” or “X” of length c where “.”, “X” denote non-mine cells and mine cells respectively, denoting each row of the mine-sweeper map you construct.

Please notice that you needn’t print the numbers on non-mine cells since these numbers can be determined by the output mine-sweeper map.

Sample Input
2
7
128

Sample Output
2 4
X…X
X…
5 19
.XXXX…XXXXX…XXXX.
XX…X…X…XX
X…X…XXXX.
XX…X.X…X…XX
.XXXX…XX…XXXX.
题意:
给一个数n,让你构造一个布雷的地图,使图中的每个数字的和为n

思路:
先把地图的所有格子都埋下雷,然后一个一个挖出来。很容易知道地图中的数字最大只可能是8,也就是周围所有格子都是雷。我们只要把n整除8,得到t代表中间挖掉的雷的个数,把n mod 8,得到的m用来处理边角

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
const int maxn = 50;
int n ;
int mp[maxn][maxn] ;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        memset(mp,0,sizeof mp);
        if(n < 25)
        {
            cout<<"1 "<<n+1<<endl;
            for(int i = 1; i <= n+1 ; i++)
            {
                if(i&1)
                    cout<<"X";
                else
                    cout<<".";
            }
            cout<<"\n";
        }
        else
        {
            double sum = n / 8 ;
            int xlen = sum / 12 ;
            int c = n % 8 ;
            cout<<"25 25\n" ;
            for(int i = 1 ; i <= xlen ; i++)
            {
                for(int j = 1 ; j <= 12 ; j++)
                    mp[i*2][j*2] = 1 ;
            }
            if(xlen * 12 < sum)
            {
                int  y = sum - xlen * 12 ;
                for(int i = 1 ; i <= y ; i++)
                    mp[xlen*2+2][2*i] = 1 ;
            }
            if(c == 1)
                mp[1][1] = 1 ;
            else if(c== 2)
                mp[1][1] = mp[1][2] = 1 ;
            else if(c == 3)
                mp[25][1] = 1 ;
            else if(c == 4)
                mp[1][1] =mp[25][1] = 1 ;
            else if(c == 5)
                mp[25][2] = 1 ;
            else if(c == 6)
                mp[25][25] = mp[25][1] = 1 ;
            else if(c == 7)
                mp[1][1] =mp[25][25] = mp[25][1] = 1  ;
            for(int i = 1 ; i <= 25 ; i++)
            {
                for(int j = 1 ; j <= 25 ; j++)
                {
                    if(mp[i][j])
                        cout<<"." ;
                    else
                        cout<<"X" ;
                }
                cout<<"\n" ;
            }
        }
    }
    return 0 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值