题解:P11020 「LAOI-6」Radiation
给出考试时的代码
不喜勿喷
分情况讨论:
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e3;
int t,n,m,s;
bool a[N + 5][N + 5];
signed main() {
cin >> t;
for(int i = 1 ; i <= t ; i ++) {
cin >> n >> m >> s;
int l = min(n,m);
for(int x = 1 ; x <= n ; x ++)
for(int y = 1 ; y <= m ; y ++)
a[x][y] = false;
//重置数组
for(int j = 1 ; j <= l ; j ++)
if(s) {
//前提是要有石头
a[j][j] = true;
s --;
} else break;
//按对角线摆放
for(int x = 1 ; x <= n ; x ++) {
for(int y = 1 ; y <= m ; y ++) {
//其余随便摆放
if(a[x][y]) {
cout << "S";
continue;
} else {
if(s) {
cout << "S";
s --;
} else {
cout << ".";
}
}
}
cout << endl;
}
}
return 0;
}