关于 洛谷基础赛 #15 T2
查看原帖
关于 洛谷基础赛 #15 T2
798795
___Segment___楼主2024/9/7 18:13

唉,蒟蒻交了 20 次,琢磨 2 小时才 38 分 QWQ。

记录:

Code:

#include<bits/stdc++.h>
using namespace std;
const int MAX = 2000;
char mp[MAX + 5][MAX + 5];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	srand(time(0));
	int T;
	cin >> T;
	while(T--) {
		int n, m, k;
		cin >> n >> m >> k;
		if(n == 2) {
			if(k == 1) {
				cout << 'S';
				for(int i = 1; i <= n; i++) {
					for(int j = 1; j <= m; j++) {
						if(i == 1 && j == 1) continue;
						cout << '.';
					}
					cout << endl; 
				}
			}
			else {
				int temp = k;
				cout << '.';
				for(int i = 1; i <= n; i++) {
					for(int j = 1; j <= m; j++) {
						if(i == 1 && j == 1) continue;
						if(i == 1 && temp == 1)
							cout << '.';
						else if(temp) {
							cout << 'S';
							temp--; 
						}
						else 
							cout << '.';
					}
					cout << endl; 
				}
			}
		}
		else if(k <= n) {
			for(int i = 1; i <= k; i++) {
				for(int j = 1; j <= (i + 1) % m; j++) cout << '.';
				cout << 'S';
				for(int j = (i + 1) % m + 1; j <= m - 1; j++) cout << '.';
				cout << endl; 
			}
			for(int i = k + 1; i <= n; i++) {
				for(int j = 1; j <= m; j++) cout << '.';
				cout << endl; 
			}
		}
		else {
			int temp = k;
			const int f = rand();
			for(int i = 1; i <= n; i++) {
				for(int j = 1; j <= m; j++) {
					mp[i][j] = ' ';
					int t = rand();
					if(t <= f / 2 && temp) {
						mp[i][j] = 'S';
						temp--;
					}
					else mp[i][j] = '.';
				}
			}
			while(temp) {
				int h = rand() * rand() % n + 1, l = rand() * rand() % m + 1;
				if(mp[h][l] == '.') {
					mp[h][l] = 'S';
					temp--;
				}
			}
			for(int i = 1; i <= n; i++) {
				for(int j = 1; j <= m; j++)
					cout << mp[i][j];
				cout << endl;
			}
		}
	}
	return 0;
}

代码用到了许多骗分法,可读性较差,还请各位大佬留步 QAQ(解答必关)。

2024/9/7 18:13
加载中...