给出考试时的代码
不喜勿喷
分情况讨论:
-
只需摆放到不同的行和列,就可以使小 U 发射最多次数的宇宙射线。
-
与情况一相同。
-
无论如何摆放,小 U 最多只要发射 次宇宙射线,所以只需要先按对角线摆放,其余石头随便摆放即可。
代码:
#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;
}