题解:CF1951D Buying Jewels
HHH6666666666 · · 题解
名副其实的脑筋急转弯 jiangly 做了半小时。
像这种构造没思路时赶紧小数据打表。把所有方案都看一遍就大概会了。
若 k>n 显然无解。
若 k=n ,显然设置一个 1 即可。
若 \frac{n}{2}<k<n 则除了 n=2k-1 的情况外均无解。
证明(没那么严谨):
假设第一个柜台定价为
剩下的情况:
第一个柜子定价
结束,就这么简单。
赛时被创飞了。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve() {
ll n, k; cin >> n >> k;
if (n == k) {
cout << "YES" << endl << 1 << endl << 1 << endl;
}
else if (k * 2 <= n) {
cout << "YES" << endl << 2 << endl << n - k + 1 << ' ' << 1 << endl;
}
else if ((n & 1) && 2 * k - 1 == n) {
cout << "YES" << endl << 2 << endl << 2 << ' ' << 1 << endl;
}
else cout << "NO" << endl;
return;
}
signed main() {
ios:: sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}