求hack
查看原帖
求hack
733553
huangluyi2008楼主2023/9/3 23:08

手玩了好多样例都找不到问题,不会写Special Judge来对拍,代码15pts

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int q, n, d, k, a[N], b[105];
int main () {
	ios :: sync_with_stdio(0);
	cin >> q;
	while (q--) {
		cin >> n >> d >> k;
		if (n == 1 || k > n - 1) {
			cout << "NO\n";
			continue;
		} 
		if (d == n - 1) {
			cout << "YES\n";
			for (int i = 2; i <= n; ++i)
				cout << 1 << ' ';
			cout << '\n';
			continue;
		}
		for (int i = 2; i <= n; ++i) a[i] = 1;
		ll sum = n - 1;
		int cnt = n - k - 1, now = n - cnt, flag = 1, j = 1; 
		b[1] = 1;
//		cout << cnt << "*\n";
		while (sum <= d && cnt >= 0) {
			for (int i = now + 1; i <= n; ++i) a[i] = now;
			sum += cnt, cnt = cnt - k, b[++j] = now; 
			if (sum >= d) {
//				cout << sum << ' ' << cnt << ' ' << now << '\n';
				if (sum == d) {
					flag = 0;
					cout << "YES\n";
					for (int i = 2; i <= n; ++i) 
						cout << a[i] << ' ';
					cout << '\n';
					break;
				}
				for (int i = n; i > now + k; --i) {
					if (sum - d <= j - 1) {
						flag = 0;
						cout << "YES\n";
						a[i] = b[j - (sum - d)];
						for (int i = 2; i <= n; ++i) 
							cout << a[i] << ' ';
						cout << '\n';
						break;
					}
					else sum -= j - 1, a[i] = 1;
				}	
				break;
			}
			now = n - cnt;
		} 
		if (flag) cout << "NO\n";
	}
	return 0;
}
2023/9/3 23:08
加载中...