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 }

原文地址:https://www.cnblogs.com/duxing201806/p/10885760.html

时间: 2024-08-30 17:01:10

Codeforces Round #560 (Div. 3) A题的相关文章

Codeforces Round #560 (Div. 3) B题

题目网址:http://codeforces.com/contest/1165/problem/B 题目大意:给出n个数,问有多少个数满足连续大于等于自然数集中的数,即以此大于等于1,2,3…… 题解:直接sort一下,然后从小到大和1,2,3……比较 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=2e5+7; 4 int a[maxn]; 5 int main() 6 { 7 int n,tot=1,ans

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱! 直接暴力求出矩阵数值,然后枚举每一个[I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了 CODE:#include <cstdio> #include <cstring>#include <queue>#include <vect

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov

Codeforces Round #560 Div. 3

题目链接:戳我 于是...风浔凌弱菜又去写了一场div.3 总的来说,真的是比较简单.......就是.......不开long long见祖宗 贴上题解-- A 给定一个数,为01串,每次可以翻转一个位置上的数,问最少几步可以使得它模\(10^x\)余\(10^y\) 从后往前贪心即可. #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<c

Codeforces Round #374 (div.2)遗憾题合集

C.Journey 读错题目了...不是无向图,结果建错图了(喵第4样例是变成无向就会有环的那种图) 并且这题因为要求路径点尽可能多 其实可以规约为限定路径长的拓扑排序,不一定要用最短路做 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm>

Codeforces Round #297 (Div. 2) E题. Anya and Cubes (中途相遇法)

题目地址:Anya and Cubes 比赛的时候居然没想起中途相遇法...这题也是属于想起来就很简单系列. 中途相遇法也叫折半搜索.就是处理前一半,把结果储存起来,再处理后一半,然后匹配前一半存储的结果. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib

Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. 首先我们根据一个维度(c维)对n个三元组排序,然后枚举答案在这个维度的取值. 此时序列被分成了两个部分,前半部分 满足所有c大于等于i 后半部分满足所有c严格小于i(即已有一个维度小于) 通过累计,我们知道此时前半部a维的最大值ma和b维的最大值mb. 显然可能存在的三元组答案,必然首先满足a维和