CF2201B Recollect Numbers 题解
Luogu
CF div2-D
CF div1-B
solution
首先划定
我们给每个字符用
考虑最小操作次数,显然最优情况为每一次都翻到一对相同的牌,即
接下来考虑最大操作次数,显然我们要最大化“浪费”的次数,尝试构造
然后考虑用这两个特殊情况推广到所有
因为
于是就解决了,时间复杂度
Code
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define lll __int128
#define db double
#define ldb long db
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define endl '\n'
#define ft first
#define sd second
using namespace std;
int T, n, k;
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> T;
while(T--) {
cin >> n >> k;
if(k < n || k >= 2 * n) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
int x = k - n + 1;
if(x == 1) {
cout << 1 << " " << 1 << " ";
} else {
cout << 1 << " " << 2 << " ";
for(int i = 1; i <= x - 2; i++) {
cout << i + 2 << " " << i << " ";
}
cout << x - 1 << " " << x << " ";
}
for(int i = 1; i <= n - x; i++) {
cout << x + i << " " << x + i << " ";
}
cout << endl;
}
}
return 0;
}
/*
Progress is impossible without change, and those who cannot change their minds cannot change anything.
NEVER GIVE UP.
*/