题目描述:
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.
You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem.
You are also given two integers 0≤y<x<n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10y modulo 10x. In other words, the obtained number should have remainder 10y when divided by 10x.
输入描述:
The first line of the input contains three integers n,x,y (0≤y<x<n≤2⋅105) — the length of the number and the integers x and y, respectively.
The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1.
输出描述:
Print one integer — the minimum number of operations you should perform to obtain the number having remainder 10y modulo 10x. In other words, the obtained number should have remainder 10y when divided by 10x.
输入:
11 5 2
11010100101
11 5 1
11010100101
输出:
1
3
题意:
你现在有一个由n个数字组成的字符串,这个串中的数字不是0就是1。
你可以对这个字符串进行操作,每次操作你可以把任意一个1变成0或者把任意一个0变成1.
现在给你两个数字x,y,你想让你的字符串形成的数字取模于10x后等于10y,请问你最少多少次操作可以满足这个要求。
题解:
瞎搞一下
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 200000 + 5;
char s[maxn];
int x,y,n;
int main(){
while(scanf("%d%d%d",&n,&x,&y)!=EOF){
int ans = 0;
scanf("%s",s + 1);
for(int i = 1; i <= n; i ++){
if(i > n - x)
ans += (s[i] != (i != n - y ? '0':'1'));
}
printf("%d\n",ans);
}
return 0;
}