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

博客介绍了Codeforces上一道题,题目给出长度为n的01数,可进行01互换,已知x和y,需求该数除以10^x余10^y次方的最小变化次数,解题思路是让后面y位数字为0且第y位为1,还给出参考代码。

题目来源: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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nuoyanli

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值