2025-11-14
Problem - 1767D - Codeforces
这题题解都看了好久
要用二叉树的想法来思考
首先字符串s不管是什么样的,只要统计1和0的数目
因为p数组顺序是任意的
所以把s按先1后0排序
接下来只要找最小可能和最大可能
- 最小:二叉树思想,x个1的话,最小值只能是\(2^x\)
- 最大:1比较完之后,\(2^y\) 个数找最小值,所以最大可能即为\(2^n-2^y+1\)
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//x=cnt1,y=cnt0
int n, x = 0, y = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n;i++){
if(s[i]=='0')
y++;
else
x++;
}
for (int i = (1 << x); i <= (1<<n)-(1 << y)+1;i++){
cout << i << " ";
}
}
Problem - 859C - Codeforces(1500)(博弈)(dp)
这题要考虑把数组分成两块
算差值的做法挺巧妙的
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=100;
int a[N], f[N];
//f[i]:表示从a[i]到a[n-1],分成两个子集的最小差值
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n;i++){
cin >> a[i];
sum += a[i];
}
f[n] = 0;
for (int i = n - 1; i >= 0;i--){
f[i] = abs(a[i] - f[i + 1]);
}
cout << (sum - f[0]) / 2 << " " << (sum + f[0]) / 2 << endl;
}
碎碎念

名字突然就绿了!!!应该是那场div2回滚,本来1198卡在灰名,然后刚刚好加上2分
虽然菜菜的,但好开心,终于打上绿名了
1500的题刷的很吃力
思维还不够
明天要做的题
几题简单题
P2347 [NOIP 1996 提高组] 砝码称重 - 洛谷
P2392 kkksc03考前临时抱佛脚 - 洛谷
(和数组分块稍稍相关)
P2430 严酷的训练 - 洛谷

浙公网安备 33010602011771号