2020 ICPC上海站 B
2020 ICPC上海站 B
题目链接:https://ac.nowcoder.com/acm/contest/9925/B
题目大意
给两个\(n*m\)的扫雷图,要求对第二个图修改不超过\((n*m)/2\)次,使得图中无雷区数字之和等于第一个图的无雷区数字之和。
思路
水题,一个扫雷图数字之和和他的翻转图是相同的,两个图至少有一个相似度超过50%,输出即可。
Code
#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define MOD 100000007
#define PI 3.1415926535898
#define INF 0x3f3f3f3f
#define MAXN 200050
#define register long long
const double EPS = 1e-8;
LL read()
{
LL w = 1, x = 0;
char ch = 0;
while (ch < '0' || ch>'9')
{
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return w * x;
}
LL n, m;
LL mp[1005][1005];
string s;
int main()
{
n = read();
m = read();
for (register int i = 1; i <= n; i++)
{
cin >> s;
for (register int j = 0; j < m; j++)
{
if (s[j] == '.')
{
mp[i][j + 1] = 1;
}
}
}
int x = 0;
for (register int i = 1; i <= n; i++)
{
cin >> s;
for (register int j = 0; j < m; j++)
{
if (s[j] == '.')
{
if (mp[i][j + 1] == 1) x++;
}
else
{
if (mp[i][j + 1] == 0) x++;
}
}
}
if (x > n * m / 2)
{
for (register int i = 1; i <= n; i++)
{
for (register int j = 1; j <= m; j++)
{
if (mp[i][j])
{
cout << '.';
}
else
{
cout << 'X';
}
}
cout << endl;
}
}
else
{
for (register int i = 1; i <= n; i++)
{
for (register int j = 1; j <= m; j++)
{
if (mp[i][j])
{
cout << 'X';
}
else
{
cout << '.';
}
}
cout << endl;
}
}
return 0;
}