#include<bits/stdc++.h>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define debug1(x) cout<<x<<" "
#define debug2(x) cout<<x<<endl
#define rep1(a,b,c) for (int a = (b) ; a < (c) ; a+=1)
#define rep2(a,b,c) for (int a = (b) ; a < (c) ; a+=2)
const int INF = 0x3f3f3f3f;
const int maxn = 1e6+10;
const int mod = 998244353;
vector<int> prime;
bool is_prime[maxn];
//埃氏筛法
void Eratosthenes(int n) {
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; ++i) is_prime[i] = true;
for (int i = 2; i <= n; ++i) {
if (is_prime[i]) {
prime.push_back(i);
if ((ll)i * i > n) continue;
for (int j = i * i; j <= n; j += i) is_prime[j] = false;
}
}
}
//快速求逆元
int inv(int a){
int b = mod-2, ans = 1;
while(b){
if(b&1) ans = (ll) ans*a%mod;
a = (ll) a*a%mod;
b >>= 1;
}
return ans;
}
char T[maxn], new_T[2*maxn];
int num_1[2*maxn], p[2*maxn], n, m=0;
void Manacher(char* str,char* new_str,int* p){
new_str[m++]='$'; new_str[m++]='#';
for(int i=0;i<n;i++) new_str[m++]=str[i], new_str[m++]='#';
new_str[m]='\0';
int mx=0,id=1,ans = 0;
for(int i=1;i<m;i++){
p[i] = id<mx ? min(p[2*id-i],mx-i) : 1;
while(new_str[i+p[i]]==new_str[i-p[i]]) p[i]++;
if(i+p[i]>mx) mx=i+p[i], id=i;
}
return ;
}
void solve(){
scanf("%s",T); n=strlen(T);
Manacher(T,new_T,p);
num_1[0] = (new_T[0]=='1'); rep1(i,0,2*n+2) num_1[i] = num_1[i-1]+(new_T[i]=='1');
int ans = num_1[2*n+1], res = ans;
// vector<int> res; res.push_back(ans);
rep1(i,0,2*n+2) if(p[i]>2){
if(new_T[i]=='1' && (p[i]-1)%2==1) continue;
int s = i-(p[i]-1), e = i+(p[i]-1);
res = min(res, ans-(num_1[e]-num_1[s]+1)/2);
// res.push_back(ans-(num_1[e]-num_1[s]+1)/2);
}
// sort(res.begin(),res.end());
printf("%d\n",res);
return ;
}
int main(){
ios::sync_with_stdio(false) ;
cin.tie(0);
cout.tie(0) ;
// int N; scanf("%d",&N); while(N--)
solve();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
2023年第十四届蓝桥杯大赛软件类省赛C&C++研究生组真题(包含代码&完整题解)
共17个文件
exe:8个
cpp:8个
md:1个
2 下载量 57 浏览量
2024-03-29
15:59:10
上传
评论
收藏 3.64MB ZIP 举报
温馨提示
部分题解:https://blog.csdn.net/weixin_45741872/article/details/137147230 2023年第十四届蓝桥杯大赛软件类省赛C&C++研究生组真题(包含代码&完整题解) C题-翻转 贪心 如果 S 中存在子串 101 或者 010,就可以将其分别变为 111 和 000,操作可以无限重复。最少翻转多少次可以把 S 变成和 T 一样。 D题-阶乘的和 STL-map 满足 `m!` 为 `sum(Ai!)` 的因数的最大的 `m` 是多少 E题- 公因数匹配 数论-质因数 找出最早出现两次质因数的位置 F题-奇怪的数 数论-位运算 长为n的数奇数位为奇数偶数位为偶数,任意连续5个数和不大于m有多少个这样的数 G题-太阳 计算几何-扫描线 太阳在(x,y),n条平行于x轴的线段,问太阳能照亮几个线段 H题-子树的大小 数据结构-m叉树 n个节点的m叉树第k个节点有几个子树 I题-高塔 数论-排列组合,数论-乘法逆元 J题-反异或 01 串 字符串-回文串
资源推荐
资源详情
资源评论
收起资源包目录
2023年第十四届蓝桥杯大赛软件类省赛C&C++研究生组真题(代码&完整题解).zip (17个子文件)
F-奇怪的数.exe 1.86MB
I-高塔.cpp 2KB
D-阶乘的和.cpp 945B
D-阶乘的和.exe 1.96MB
E-公因数匹配.exe 1.92MB
I-高塔.exe 1.93MB
E-公因数匹配.cpp 2KB
J-反异或01串.cpp 2KB
C-翻转.exe 1.83MB
G-太阳.exe 1.99MB
J-反异或01串.exe 1.93MB
C-翻转.cpp 597B
完整题解.md 5KB
F-奇怪的数.cpp 2KB
子树的大小.cpp 2KB
G-太阳.cpp 2KB
子树的大小.exe 1.93MB
共 17 条
- 1
资源评论
温柔说给风
- 粉丝: 9885
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功