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 ;
}