Codeforces Round #560 (Div. 3)A-E
A. Remainder
You are given a huge decimal number consisting of nn 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<n0≤y<x<n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10y10y modulo 10x10x. In other words, the obtained number should have remainder 10y10y when divided by 10x10x.
The first line of the input contains three integers n,x,yn,x,y (0≤y<x<n≤2⋅1050≤y<x<n≤2⋅105) — the length of the number and the integers xxand yy, respectively.
The second line of the input contains one decimal number consisting of nn 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 10y10y modulo 10x10x. In other words, the obtained number should have remainder 10y10y when divided by 10x10x.
11 5 2 11010100101
1
11 5 1 11010100101
3
In the first example the number will be 1101010010011010100100 after performing one operation. It has remainder 100100 modulo 100000100000.
In the second example the number will be 1101010001011010100010 after performing three operations. It has remainder 1010 modulo 100000100000.
思路:只需要看需要的位数
代码:
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<queue> #include<stack> #include<set> #include<vector> #include<map> #include<cmath> const int maxn=1e5+5; typedef long long ll; using namespace std; char a[2*maxn]; int main() { int n,x,y; cin>>n>>x>>y; scanf("%s",a); int sum=0; for(int t=n-1;t>=n-x;t--) { if(a[t]=='0'&&t!=n-y-1) { continue; } else if(a[t]=='1'&&t!=n-y-1) { sum++; } else if(a[t]=='1'&&t==n-y-1) { continue; } else if(a[t]=='0'&&t==n-y-1) { sum++; } } printf("%d",sum); return 0; }
B. Polycarp Training
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 从零开始开发一个 MCP Server!
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档