Codeforces Round #560 (Div. 3) A题

题目网址:http://codeforces.com/contest/1165/problem/A

题目大意:给定一行01串,开头必是1,length为n,可对串进行变化,0变成1,1变成0,问经过最少的变化,该串mod 10^x==10^y.(^是乘方),输出变化次数。

题解:简单分析可知,比如串是1001000,则mod 1000 == 0,mod 10000 == 1000,所以直接在n-x之和判断即可。

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int maxn=2e5+7;
 5 char str[maxn];
 6 int main()
 7 {
 8     int n,x,y;
 9     cin>>n>>x>>y;
10     scanf("%s",str+1);
11     int ans=0;
12     for(int i=n-x+1;i<=n;i++) {
13         if(i==(n-y)&&str[i]=='0') ans++;
14         if(i!=(n-y)&&str[i]=='1') ans++; 
15     }
16     cout<<ans<<endl;
17     return 0;
18 }
View Code
原文地址:https://www.cnblogs.com/duxing201806/p/10885760.html