Codeforces Round #560 (Div. 3) A.Remainder

题目来源:https://codeforces.com/contest/1165/problem/A

题意:给你一个长度为n的只包含01的数,定义可以01互换,给你一个x一个y,让你求除以10^x余10^y次方的最小变化次数。

思路:求变为后面y位数字为0 第y为1。

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define PII pair<int,int>
#define PB push_back
#define POP pop_back
#define FI first
#define SE second
#define endl '\n'
#define ls x<<1
#define rs x<<1|1
const int N=3e6+7,mod=1e9+7,INF=1e9;
int n,m,x,y;
int a[N],b[N];
char s[N],ss[N];
int main()
{
    cin>>n>>x>>y;
    scanf("%s",s);
    int ans=0;
    for(int i=n-x;i<n;i++){
        if(i==n-y-1&&s[i]=='0')ans++;
        else if(i!=n-y-1&&s[i]=='1')ans++;
    }
    cout<<ans;
    return 0;
}

 

全部评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务