个人认为很唐的一道题,考虑到不少人可能懒得写,我这里给大家发个代码叭,还有一点点题解(因为真的不是很难)。这是题面:
然后我来讲讲怎么做,不觉得会有多少人题目意思都理解不了叭?这个就是要求你构造一个n*m的方阵,满足经过无限次四种变换后恰好会出现四种本质不同的状态,这里的本质不同就是坐标不同的意思,大家可以好好理解下,然后我们通过手玩一部分的样例可以发现本质不同最多只会有13种状态,即k > 13的时候输出”No“,然后k在1,2,3,4,5,6,7,8,9,10,11,12,13的这几种情况中,k = 8,10,12的时候是完全不行的,对于k = 5的时候我们发现当gcd(n,m) = 1的时候也是不可行的,上述是一部分的不可行情况。
我们的思路就是枚举k,对于每个k我们需要考虑n和m都比较小的时候也会出现不可行方案,一般来讲就是分n <= 2,m <= 2或者n <= 3和m <= 3的情况需要特殊考虑,因此剩下的我们就分k的大小构造答案就行:
k = 1:全部站满
k = 2:空出一行或者一列
k = 3:空出不相邻的两行或者两列
k = 4:只放在(1,1)
k = 5: 一共存放LCM(n,m)个人,排列方式为每行逐渐平移下去,可以手玩一下,比如n = m = 3的情况:
k = 6:放一个人到四个边界上的不同于端点的一点
如n = 2,m = 3:
k = 7:第一行放满,然后把第一个人放到第二行第一个或者列同理:
k = 9:直接在(2,2)放上一个,或者对于n = 2,m = 3或n = 3,m = 2的情况在(1,1)(n,m)各方一个就行
k = 11:对于n >= 2 && m >= 4 || n >= 4 && m >= 2,在(1,2)(2,1)(1,4)或者(4,1)上共放三个,然后对于n = 3,m = 3的时候在(1,1)和(3,2)各放一个即可
k = 13:直接放在(1 , 3)和(3,1)
上述对于小范围数据需要加特判,然后没什么思维难度,对细节处理有一定要求,我直接放下代码:
#include<bits/stdc++.h>
#define Alex std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);
#define int long long
#define double long double
const int QAQ = 0;
const int mod = 998244353;
const double pi = std::acos(-1.0);
const double eps = 1e-10;char a[2005][2005];signed main()
{Alex;int _;_ = 1;std::cin>>_;while(_--){int n,m,k;std::cin>>n>>m>>k;for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';if(k > 13){std::cout<<"No"<<'\n';continue;}if(k >= 8 && k % 2 == 0){std::cout<<"No"<<'\n';continue;}if(k == 5 && std::__gcd(n,m) == 1){std::cout<<"No"<<'\n';continue;}if(k == 1){std::cout<<"Yes"<<'\n';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<'*';std::cout<<'\n';}continue;}if(k == 2){if(n == 1 && m == 1){std::cout<<"No"<<'\n';continue;}std::cout<<"Yes"<<'\n';if(n > 1){for(int i = 1;i <= m;i++) std::cout<<'-';std::cout<<'\n';for(int i = 2;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<'*';std::cout<<'\n';} }else{for(int i = 1;i <= n;i++){std::cout<<'-';for(int j = 2;j <= m;j++) std::cout<<'*';std::cout<<'\n';}}continue;}if(k == 3){if(n < 3 && m < 3){if(n == 1 && m == 1){std::cout<<"No"<<'\n';}if(n == 1 && m == 2){std::cout<<"No"<<'\n';}if(n == 2 && m == 1){std::cout<<"No"<<'\n';}if(n == 2 && m == 2){std::cout<<"No"<<'\n';}continue;}std::cout<<"Yes"<<'\n';if(n >= 3){for(int i = 1;i <= m;i++) std::cout<<'-';std::cout<<'\n';for(int i = 2;i <= n - 1;i++){for(int j = 1;j <= m;j++) std::cout<<'*';std::cout<<'\n';}for(int i = 1;i <= m;i++) std::cout<<'-';std::cout<<'\n';}else{for(int i = 1;i <= n;i++){std::cout<<'-';for(int j = 2;j <= m - 1;j++) std::cout<<'*';std::cout<<'-';std::cout<<'\n';}}continue;}if(k == 4){if(n == 1 || m == 1){std::cout<<"No"<<'\n';continue;}if(n >= 2 && m >= 2){std::cout<<"Yes"<<'\n';std::cout<<'*';for(int j = 2;j <= m;j++) std::cout<<'-';std::cout<<'\n';for(int i = 2;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<'-';std::cout<<'\n';}}continue;}if(k == 5){std::cout<<"Yes"<<'\n';int lcm = n * m / std::__gcd(n,m);int every = lcm / n;for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';int t = 1;every = m / every;for(int i = 1;i <= n;i++){for(int j = t;j <= m;j = j + every) a[i][j] = '*';t++;if(t == every + 1) t = 1;}for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}continue;}if(k == 6){if(n >= 3 && m >= 2 || n >= 2 && m >= 3){std::cout<<"Yes"<<'\n';if(n >= 3){for(int i = 1;i <= m;i++) std::cout<<'-';std::cout<<'\n';std::cout<<'*';for(int i = 2;i <= m;i++) std::cout<<'-';std::cout<<'\n';for(int i = 3;i <= n;i++) {for(int j = 1;j <= m;j++) std::cout<<'-';std::cout<<'\n';}}else{std::cout<<'-'<<'*';for(int i = 3;i <= m;i++) std::cout<<'-';std::cout<<'\n';for(int i = 2;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<'-';std::cout<<'\n';}}}else{std::cout<<"No"<<'\n';continue;}continue;}if(k == 7){if(n >= 3 && m >= 2 || m >= 3 && n >= 2){std::cout<<"Yes"<<'\n';for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';if(n >= 3){for(int i = 1;i <= m;i++) a[1][i] = '*';std::swap(a[1][1],a[2][1]);for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}}else{for(int i = 1;i <= n;i++) a[i][1] = '*';std::swap(a[1][1],a[1][2]);for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}}}else{std::cout<<"No"<<'\n';continue;}continue;}if(k == 9){if(n >= 3 && m >= 3){std::cout<<"Yes"<<'\n';for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';a[2][2] = '*';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}}elseif(n == 2 && m >= 3 || n >= 3 && m == 2){std::cout<<"Yes"<<'\n';for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';a[1][1] = '*';a[n][m] = '*';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}}else{std::cout<<"No"<<'\n';continue;}continue;}if(k == 11){if(n >= 2 && m >= 4 || n >= 4 && m >= 2){std::cout<<"Yes"<<'\n';if(n >= 2 && m >= 4){for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';a[1][2] = '*',a[2][1] = '*',a[1][4] = '*';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}}else{for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';a[1][2] = '*',a[2][1] = '*',a[4][1] = '*';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';} }}elseif(n == 3 && m == 3){std::cout<<"Yes"<<'\n';for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';a[1][1] = '*';a[3][2] = '*';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n';}}else{std::cout<<"No"<<'\n';continue;}continue;}if(k == 13){if(n >= 3 && m >= 3){std::cout<<"Yes"<<'\n';for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++) a[i][j] = '-';a[1][3] = '*';a[3][1] = '*';for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++) std::cout<<a[i][j];std::cout<<'\n'; } }else{std::cout<<"No"<<'\n';continue;}continue;}}return QAQ;
}
OK辣,那么这道题目就被秒了~