CodeForces 1551D2 : Domino (hard version) 模拟
作者:互联网
传送门
题意
给你一个 n ∗ m n * m n∗m矩阵,需要放若干个多米诺骨牌,要求其中水平的有 k k k个
分析
锻炼一下模拟能力吧
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
int n,m,k;
int a[N][N];
int main() {
int T;
read(T);
while(T--){
memset(a,-1,sizeof a);
read(n),read(m),read(k);
bool flag = false;
if(n * m < k * 2) puts("NO"),flag = true;
else if(m % 2){
if((m - 1) * n < k * 2) puts("NO"),flag = true;
else if(k % 2 == 0) puts("YES");
else puts("NO"),flag = true;
}
else if(n % 2){
if((k - m / 2) >= 0 && (k - m / 2) % 2 == 0) puts("YES");
else puts("NO"),flag = true;
}
else{
if(k & 1) puts("NO"),flag = true;
else puts("YES");
}
if(flag) continue;
if(m % 2){
for(int i = 1;i < m && k;i += 2){
for(int j = 1;j <= n && k;j++,k--){
int x = a[j - 1][i] + 1;
if(x == a[j][i - 1]) x++;
x %= 26;
a[j][i] = a[j][i + 1]= x;
}
}
for(int i = 1;i <= n;i += 2)
for(int j = 1;j <= m;j++){
if(a[i][j] != -1) continue;
int x = a[i - 1][j] + 1;
if(x == a[i][j - 1]) x++;
x %= 26;
if(x == a[i + 1][j - 1])x++;
x %= 26;
a[i][j] = a[i + 1][j] = x;
}
}
else if(n % 2){
for(int i = 1;i <= m;i += 2,k--){
int x = a[1][i - 1] + 1;
x++;
x %= 26;
a[1][i] = a[1][i + 1] = x;
}
for(int i = 1;i <= m && k;i += 2){
for(int j = 1;j <= n && k;j++){
if(a[j][i] != -1) continue;
k--;
int x = a[j - 1][i] + 1;
if(x == a[j][i - 1]) x++;
x %= 26;
a[j][i] = a[j][i + 1]= x;
}
}
for(int i = 2;i <= n;i += 2)
for(int j = 1;j <= m;j++){
if(a[i][j] != -1) continue;
int x = a[i - 1][j] + 1;
if(x == a[i][j - 1]) x++;
x %= 26;
if(x == a[i + 1][j - 1])x++;
x %= 26;
a[i][j] = a[i + 1][j] = x;
}
}
else{
for(int i = 1;i <= m && k;i += 2){
for(int j = 1;j <= n && k;j++,k--){
int x = a[j - 1][i] + 1;
if(x == a[j][i - 1]) x++;
x %= 26;
a[j][i] = a[j][i + 1]= x;
}
}
for(int i = 1;i <= n;i += 2)
for(int j = 1;j <= m;j++){
if(a[i][j] != -1) continue;
int x = a[i - 1][j] + 1;
if(x == a[i][j - 1]) x++;
x %= 26;
if(x == a[i + 1][j - 1])x++;
x %= 26;
a[i][j] = a[i + 1][j] = x;
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++) printf("%c",a[i][j] + 'a');
puts("");
}
}
return 0;
}
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
标签:26,puts,int,Domino,hard,1551D2,else,++,flag 来源: https://blog.csdn.net/tlyzxc/article/details/119063735