0
点赞
收藏
分享

微信扫一扫

A. Remainder(字符串问题) Codeforces Round #560 (Div. 3)

倪雅各 2022-06-24 阅读 77


原题链接: ​​https://codeforces.com/problemset/problem/1165/A​​​A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_ios
样例:

Input
11 5 2
11010100101
Output
1
Input
11 5 1
11010100101
Output
3

题意: 给你一个二进制字符串,你可以进行修改操作。你需要使这个二进制字符串的值对于给定的A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_ios_02A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_03A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_04取模之后的值为A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_05,问你最少需要进行多少次修改操作。

解题思路: 这个题目我们不能真的去取模,而是分析一下对A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_04取模余下的是什么,什么会被消去。即把A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_04也展成二进制字符串,那么不小于第A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_字符串_08位的全部都会被消去,而剩下的就是在低于第A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_字符串_08的二进制,而我们如果想得到最后的值为A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_05即剩余的二进制字符串要与A. Remainder(字符串问题)  Codeforces Round #560 (Div. 3)_#define_11的二进制字符串相同,故我们统计我们要修改的即可

AC代码:

/
*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
int n,x,y;
string str;
while(cin>>n>>x>>y){
cin>>str;
int sum=0;
if(str[n-y-1]!='1')sum++;
for(int i=n-1;i>n-x-1;i--){
if(i!=n-y-1){
if(str[i]!='0')
sum++;
}
}
cout<<sum<<endl;
}
return 0;
}


举报

相关推荐

0 条评论