Codeforces Round #560 (Div. 3)A-E
A. Remainder
standard output
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+;
- typedef long long ll;
- using namespace std;
- char a[*maxn];
- int main()
- {
- int n,x,y;
- cin>>n>>x>>y;
- scanf("%s",a);
- int sum=;
- for(int t=n-;t>=n-x;t--)
- {
- if(a[t]==''&&t!=n-y-)
- {
- continue;
- }
- else if(a[t]==''&&t!=n-y-)
- {
- sum++;
- }
- else if(a[t]==''&&t==n-y-)
- {
- continue;
- }
- else if(a[t]==''&&t==n-y-)
- {
- sum++;
- }
- }
- printf("%d",sum);
- return ;
- }
B. Polycarp Training
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 11 problem, during the second day — exactly 22 problems, during the third day — exactly 33 problems, and so on. During the kk-th day he should solve kk problems.
Polycarp has a list of nn contests, the ii-th contest consists of aiai problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly kk problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least kk problems that Polycarp didn't solve yet during the kk-th day, then Polycarp stops his training.
How many days Polycarp can train if he chooses the contests optimally?
The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of contests.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤2⋅1051≤ai≤2⋅105) — the number of problems in the ii-th contest.
Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.
- 4
- 3 1 4 1
- 3
- 3
- 1 1 1
- 1
- 5
- 1 1 1 2 2
- 2
思路:优先队列
代码:
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<queue>
- #include<stack>
- #include<set>
- #include<map>
- #include<algorithm>
- #include<vector>
- const int maxn=2e5+;
- typedef long long ll;
- using namespace std;
- priority_queue<int,vector<int>,greater<int> >q;
- int main()
- {
- int n,x;
- cin>>n;
- for(int i=;i<=n;i++)
- {
- cin>>x;
- q.push(x);
- }
- int ans=;
- for(int i=;;i++)
- {
- while(!q.empty())
- {
- x=q.top();q.pop();
- if(x>=i)
- {
- x-=i;
- ans=i;
- break;
- }
- }
- if(q.empty())
- break;
- }
- cout<<ans;
- }
C. Good String
Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.
You are given a string ss, you have to delete minimum number of characters from this string so that it becomes good.
The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of characters in ss.
The second line contains the string ss, consisting of exactly nn lowercase Latin letters.
In the first line, print one integer kk (0≤k≤n0≤k≤n) — the minimum number of characters you have to delete from ss to make it good.
In the second line, print the resulting string ss. If it is empty, you may leave the second line blank, or not print it at all.
- 4
- good
- 0
- good
- 4
- aabc
- 2
- ab
- 3
- aaa
- 3
用队列模拟一下取不取的过程
代码:
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<algorithm>
- #include<queue>
- #include<stack>
- #include<set>
- #include<vector>
- #include<map>
- #include<cmath>
- const int maxn=1e5+;
- typedef long long ll;
- using namespace std;
- char str[*maxn];
- int main()
- {
- int n;
- cin>>n;
- scanf("%s",str+);
- int sum=;
- char ss=str[];
- queue<char>q;
- q.push(ss);
- for(int t=;t<=n;t++)
- {
- if(sum%==&&str[t]==ss)
- {
- continue;
- }
- sum++;
- ss=str[t];
- q.push(str[t]);
- }
- if(sum%==)
- {
- sum--;
- }
- printf("%d\n",n-sum);
- int cnt=;
- while(!q.empty())
- {
- if(cnt==sum)
- {
- break;
- }
- cnt++;
- printf("%c",q.front());
- q.pop();
- }
- printf("\n");
- return ;
- }
D. Almost All Divisors
We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means that there are all divisors except 11 and xx in the list.
Your task is to find the minimum possible integer xx that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.
You have to answer tt independent queries.
The first line of the input contains one integer tt (1≤t≤251≤t≤25) — the number of queries. Then tt queries follow.
The first line of the query contains one integer nn (1≤n≤3001≤n≤300) — the number of divisors in the list.
The second line of the query contains nn integers d1,d2,…,dnd1,d2,…,dn (2≤di≤1062≤di≤106), where didi is the ii-th divisor of the guessed number. It is guaranteed that all values didi are distinct.
For each query print the answer to it.
If the input data in the query is contradictory and it is impossible to find such number xx that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible xx.
- 2
- 8
- 8 2 12 6 4 24 16 3
- 1
- 2
- 48
- 4
前面有此题的思路和代码
E. Two Arrays and Sum of Functions
You are given two arrays aa and bb, both of length nn.
Let's define a function f(l,r)=∑l≤i≤rai⋅bif(l,r)=∑l≤i≤rai⋅bi.
Your task is to reorder the elements (choose an arbitrary order of elements) of the array bb to minimize the value of ∑1≤l≤r≤nf(l,r)∑1≤l≤r≤nf(l,r). Since the answer can be very large, you have to print it modulo 998244353998244353. Note that you should minimize the answer but not its remainder.
The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in aa and bb.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106), where aiai is the ii-th element of aa.
The third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bj≤1061≤bj≤106), where bjbj is the jj-th element of bb.
Print one integer — the minimum possible value of ∑1≤l≤r≤nf(l,r)∑1≤l≤r≤nf(l,r) after rearranging elements of bb, taken modulo 998244353998244353. Note that you should minimize the answer but not its remainder.
- 5
- 1 8 7 2 4
- 9 7 2 9 3
- 646
- 1
- 1000000
- 1000000
- 757402647
- 2
- 1 3
- 4 2
- 20
思考贡献次数和排序
注意取模
代码:
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<queue>
- #include<stack>
- #include<set>
- #include<map>
- #include<algorithm>
- #include<vector>
- const int maxn=1e5+;
- typedef long long ll;
- using namespace std;
- ll a[*maxn],b[maxn*];
- bool cmp(int x,int y)
- {
- return x>y;
- }
- int main()
- {
- int n;
- cin>>n;
- for(int t=;t<n;t++)
- {
- scanf("%lld",&a[t]);
- a[t]=(a[t]*(n-t)*(t+));
- }
- for(int t=;t<n;t++)
- {
- scanf("%lld",&b[t]);
- }
- sort(a,a+n);
- sort(b,b+n,cmp);
- ll ans=;
- for(int t=;t<n;t++)
- {
- ans=(ans%+((a[t]%)*(b[t]%))%)%;
- }
- printf("%lld",ans);
- return ;
- }
Codeforces Round #560 (Div. 3)A-E的更多相关文章
- Codeforces Round #560 (Div. 3) Microtransactions
Codeforces Round #560 (Div. 3) F2. Microtransactions (hard version) 题意: 现在有一个人他每天早上获得1块钱,现在有\(n\)种商品 ...
- A. Remainder Codeforces Round #560 (Div. 3)
A. Remainder Codeforces Round #560 (Div. 3) You are given a huge decimal number consisting of nn dig ...
- Codeforces Round #560 Div. 3
题目链接:戳我 于是...风浔凌弱菜又去写了一场div.3 总的来说,真的是比较简单.......就是.......不开long long见祖宗 贴上题解-- A 给定一个数,为01串,每次可以翻转一 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- 41-native关键字的理解
使用 native 关键字说明这个方法是原生函数,也就是这个方法是用 C/C++等非Java 语言实现的,并且被编译成了 DLL,由 java 去调用. (1)为什么要用 native 方法 java ...
- hashCode竟然不是根据对象内存地址生成的?还对内存泄漏与偏向锁有影响?
起因 起因是群里的一位童鞋突然问了这么问题: 如果重写 equals 不重写 hashcode 会有什么影响? 这个问题从上午10:45 开始陆续讨论,到下午15:39 接近尾声 (忽略这形同虚设的马 ...
- 008_用go语言实现简单的冒泡排序
冒泡排序是各个语言中的基本排序算法,本次我们用go语言实现简单的冒泡排序 package main import "fmt" // [13,10,5,7,2] // [10,13, ...
- 使用HttpClient 发送 GET、POST(FormData、Raw)、PUT、Delete请求及文件上传
httpclient4.3.6 package org.caeit.cloud.dev.util; import java.io.File; import java.io.IOException; i ...
- javascript Math对象 、Date对象笔记
Math对象 Math 是一个内置对象, 它具有数学常数和函数的属性和方法.不是一个函数对象. Math数学对象不是构造函数使用的时候不需要new来调用,可以直接使用里面的属性和方法 ...
- proxy的实现(代理)
29.proxy的实现 (代理) get方法 //定义一个对象personvar person = {"name":"张三”};//创建一个代理对象pro, 代理pers ...
- Spring Cloud 之服务注册中心高可用
服务注册中心高可用 服务注册中心 eureka-server 高可用实施 版本 Spring Boot 版本 # Spring Boot 版本: <parent> <groupId& ...
- 一篇看懂Socket开发
Socket[套接字]是什么,对于这个问题,初次接触的开发人员一般以为他只是一个通讯工具. Socket接口是TCP/IP网络的API,Socket接口定义了许多函数或例程,程序员可以用它们来开发 T ...
- 基于注解的DI
目录 一.使用注解的步骤 二.@Component 三.@Value 四.@Autowired 五.@Qualifier 六.@Resource 七.XML和注解对比 通过spring的注解完成对ja ...
- Vue 给子组件绑定v-model
父组件使用子组件时,使用v-model指令,在子组件中使用value获取props的值 父组件 <template> <div style="margin:20px;dis ...