当前位置:网站首页>codeforces每日5题(均1600)-第二十八天
codeforces每日5题(均1600)-第二十八天
2022-08-04 17:11:00 【汤键.】
Ivan and Powers of Two
题面翻译
有一个由 n n n 个非负整数组成的序列 a 1 a_1 a1 到
a n a_n an,这个序列保证单调不降。接着,小华将上述序列作为2的次幂,写下了另一个序列:2的 a 1 a_1 a1 次幂到2的 a n a_n an 次幂。
现在他想知道,最少要在这个序列中添加多少个形式为 2 x 2^x 2x 的数( x x x 为非负整数),才能使这个序列所有整数的和为 2 v − 1 2^v-1 2v−1,其中 v v v 为某个非负整数。
题目描述
Ivan has got an array of n n n non-negative integers a 1 , a 2 , . . . , a n a_{1},a_{2},...,a_{n} a1,a2,...,an .
Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2 a 1 , 2 a 2 , . . . , 2 a n 2^{a_{1}},2^{a_{2}},...,2^{a_{n}} 2a1,2a2,...,2an on a piece of paper.
Now he wonders, what minimum number of integers of form 2 b 2^{b} 2b ( b > = 0 ) (b>=0) (b>=0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2 v − 1 2^{v}-1 2v−1 for some integer v v v ( v > = 0 ) (v>=0) (v>=0) .
Help Ivan, find the required quantity of numbers.
输入格式
The first line contains integer n n n ( 1 < = n < = 1 0 5 1<=n<=10^{5} 1<=n<=105 ).
The second input line contains n n n space-separated integers a 1 , a 2 , . . . , a n a_{1},a_{2},...,a_{n} a1,a2,...,an ( 0 < = a i < = 2 ⋅ 1 0 9 ) (0<=a_{i}<=2·10^{9}) (0<=ai<=2⋅109) .
It is guaranteed that a 1 < = a 2 < = . . . < = a n a_{1}<=a_{2}<=...<=a_{n} a1<=a2<=...<=an .
输出格式
Print a single integer — the answer to the problem.
样例 #1
样例输入 #1
4
0 1 1 1
样例输出 #1
0
样例 #2
样例输入 #2
1
3
样例输出 #2
3
提示
In the first sample you do not need to add anything, the sum of numbers already equals 2 3 − 1 = 7 2^{3}-1=7 23−1=7 .
In the second sample you need to add numbers 2 0 , 2 1 , 2 2 2^{0},2^{1},2^{2} 20,21,22 .
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
int n,v,ans,x;
map<int,int>sum;
int main(){
cin>>n;
for(int i=1;i<=n;++i){
cin>>x;
while(sum.count(x))
sum.erase(x++);
++sum[x];
v=max(v,x);
}
cout<<v+1-sum.size()<<endl;
return 0;
}
Perfect Pair
题面翻译
题目大意:定义一对数(x,y),若x、y中至少有一个大于等于m,则称(x,y)对m完美。
现在给定一对数(x,y),允许把其中的一个数换成x+y,问把(x,y)变成对m完美的数对至少需要几次操作。
题目描述
Let us call a pair of integer numbers m m m -perfect, if at least one number in the pair is greater than or equal to m m m .
Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers x x x , y y y are written on the blackboard.
It is allowed to erase one of them and replace it with the sum of the numbers, ( x + y ) (x+y) (x+y) .
What is the minimum number of such operations one has to perform in order to make the given pair of integers m m m -perfect?
输入格式
Single line of the input contains three integers x x x , y y y and m m m ( − 1 0 18 < = x -10^{18}<=x −1018<=x , y y y , m < = 1 0 18 m<=10^{18} m<=1018 ).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier.
输出格式
Print the minimum number of operations or “-1” (without quotes), if it is impossible to transform the given pair to the m m m -perfect one.
样例 #1
样例输入 #1
1 2 5
样例输出 #1
2
样例 #2
样例输入 #2
-1 4 15
样例输出 #2
4
样例 #3
样例输入 #3
0 -1 5
样例输出 #3
-1
提示
In the first sample the following sequence of operations is suitable: (1, 2) (3, 2)
(5, 2).
In the second sample: (-1, 4) (3, 4)
(7, 4)
(11, 4)
(15, 4).
Finally, in the third sample x x x , y y y cannot be made positive, hence there is no proper sequence of operations.
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
ll x,y,m,s=0;
int main(){
cin>>x>>y>>m;
if(x>=m||y>=m){
puts("0");
return 0;
}
else if(x<=0&&y<=0){
puts("-1");
return 0;
}
else if(x*y<0){
if(x<y){
s+=(-x)/y;
x=x%y;
}
else{
s+=(-y)/x;
y=y%x;
}
}
while(x<m&&y<m){
if(x>y)swap(x,y);
x+=y;
s++;
}
cout<<s;
return 0;
}
Ciel and Flowers
题面翻译
Fox Ciel有r朵红花,g朵绿花和b朵蓝花。她想用这些花做几个花束。
有四种类型的花束:
- 制作“红色花束”,要3朵红花
- 制作“绿色花束”,要3朵绿花
- 制作“蓝色花束”,要3朵蓝花
- 制作“混合花束”,要1朵红,1朵绿和1朵蓝花
输出可以制作的最大数量的花束。
题目描述
Fox Ciel has some flowers: r r r red flowers, g g g green flowers and b b b blue flowers.
She wants to use these flowers to make several bouquets.
There are 4 types of bouquets:
- To make a “red bouquet”, it needs 3 red flowers.
- To make a “green bouquet”, it needs 3 green flowers.
- To make a “blue bouquet”, it needs 3 blue flowers.
- To make a “mixing bouquet”, it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
输入格式
The first line contains three integers r r r , g g g and b b b ( 0 < = r , g , b < = 1 0 9 0<=r,g,b<=10^{9} 0<=r,g,b<=109 ) — the number of red, green and blue flowers.
输出格式
Print the maximal number of bouquets Fox Ciel can make.
样例 #1
样例输入 #1
3 6 9
样例输出 #1
6
样例 #2
样例输入 #2
4 4 4
样例输出 #2
4
样例 #3
样例输入 #3
0 0 0
样例输出 #3
0
提示
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
ll a,b,c,ans;
int main(){
cin>>a>>b>>c;
ans=a/3+b/3+c/3+min(a%3,min(b%3,c%3));
if(a>=1&&b>=1&&c>=1) ans=max(ans,(a-1)/3+(b-1)/3+(c-1)/3+1+min((a+2)%3,min((b+2)%3,(c+2)%3)));
if(a>=2&&b>=2&&c>=2) ans=max(ans,(a-2)/3+(b-2)/3+(c-2)/3+2+min((a+1)%3,min((b+1)%3,(c+1)%3)));
printf("%d\n",ans);
return 0;
}
Secrets
题面翻译
这个世界上只有这样面值的硬币:1,3,9,27,81,…有一个商人,某一天遇到了一个顾客,他购买了价值n的商品,发现用自己的硬币无法付给商人刚好n的钱。那个顾客会给商人大于等于n的钱且使得给商人的硬币数量最少。
在这个顾客有的硬币可能的各种情况下,请问这个商人最多可能收到多少硬币?
题目描述
Gerald has been selling state secrets at leisure.
All the secrets cost the same: n n n marks.
The state which secrets Gerald is selling, has no paper money, only coins.
But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on.
There are no coins of other denominations.
Of course, Gerald likes it when he gets money without the change.
And all buyers respect him and try to give the desired sum without change, if possible.
But this does not always happen.
One day an unlucky buyer came.
He did not have the desired sum without change.
Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible.
What is the maximum number of coins he could get?
The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n n n marks without change.
For each such combination calculate the minimum number of coins that can bring the buyer at least n n n marks.
Among all combinations choose the maximum of the minimum number of coins. This is the number we want.
输入格式
The single line contains a single integer n n n ( 1 < = n < = 1 0 17 1<=n<=10^{17} 1<=n<=1017 ).
Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输出格式
In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.
样例 #1
样例输入 #1
1
样例输出 #1
1
样例 #2
样例输入 #2
4
样例输出 #2
2
提示
In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin.
In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.
In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins.
The buyer cannot give three coins as he wants to minimize the number of coins that he gives.
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
ll n,s=1;
int main(){
cin>>n;
while(n%s==0) s*=3;
cout<<n/s+1;
return 0;
}
Rational Resistance
题面翻译
题意翻译简化:
迈克有许多阻值为 1 Ω 1Ω 1Ω 的电阻,通过串联、并联的方式组装为一个电阻为 a b \frac{a}{b} ba 的元件,求所需的最少电阻数量。
数据:
1 < = a , b < = 1 0 18 1<=a,b<=10^{18} 1<=a,b<=1018,保证 a b \frac{a}{b} ba 已经最简,保证有解。
题目描述
Mad scientist Mike is building a time machine in his spare time.
To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R 0 = 1 R_{0}=1 R0=1 .
Elements with other resistance can be constructed from these resistors.
In this problem, we will consider the following as elements:
- one resistor;
- an element and one resistor plugged in sequence;
- an element and one resistor plugged in parallel.
With the consecutive connection the resistance of the new element equals R = R e + R 0 R=R_{e}+R_{0} R=Re+R0 .
With the parallel connection the resistance of the new element equals . In this case R e R_{e} Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction .
Determine the smallest possible number of resistors he needs to make such an element.
输入格式
The single input line contains two space-separated integers a a a and b b b ( 1 < = a , b < = 1 0 18 1<=a,b<=10^{18} 1<=a,b<=1018 ).
It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists.
输出格式
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
样例 #1
样例输入 #1
1 1
样例输出 #1
1
样例 #2
样例输入 #2
3 2
样例输出 #2
3
样例 #3
样例输入 #3
199 200
样例输出 #3
200
提示
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively.
Then, we get an element with resistance . We cannot make this element using two resistors.
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
ll a,b,c,s=0;
int main(){
cin>>a>>b;
while(b!=0){
s+=a/b;
c=a%b;
a=b,b=c;
}
cout<<s;
return 0;
}
边栏推荐
- Nacos集群搭建
- 如何模拟后台API调用场景,很细!
- R语言缺失时间序列的填充及合并:补齐时间序列数据中所有缺失的时间索引、使用merge函数合并日期补齐之后的时间序列数据和另外一个时间序列数据(补齐左侧数据)
- What does the product system of a digital financial enterprise look like?
- 海报 | 夏季高温,危化品安全风险的注意事项必须get!
- Codeforces Round #811 (Div. 3)
- 多线程学习笔记-3.并发容器
- NLP未来,路在何方?从学术前沿和业界热点谈起
- The use of QCompleter for Qt auto-completion
- 】 【 LeetCode daily one problem - 540. The order of a single element of the array
猜你喜欢
JVM内存和垃圾回收-08.方法区
Flutter实战-请求封装(四)之gzip报文压缩
【LeetCode每日一题】——540.有序数组中的单一元素
Boost library study notes (1) Installation and configuration
要有遥不可及的梦想,也要有脚踏实地的本事
8月5日,麒麟信安邀您相约鲲鹏开发者创享日·长沙站!
【小程序】实现发动态功能
浅谈运用低代码技术如何实现物流企业的降本增效
学习探索-网站中引入百度统计
15 days to upgrade to fight monsters and become a virtual fashion creator
随机推荐
Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency
Catering Supply Chain Management System
Unity Apple登录接入
taro 滚动组件ScrollView
容器化 | 在 NFS 备份恢复 RadonDB MySQL 集群数据
Learning to Explore - Setting the Foreground Color for Fonts
机器学习(十六):主成成分分析(PCA)
Mobile BesTV_R3300-L_S905L_8189_wire brush firmware package
域名哪家便宜?怎么买便宜域名?
码蹄集 - MT3029 - 新月轩就餐
【商家联盟】云平台—异业联盟,打造线上线下商业相结合的系统
response的contentType 几种类型
shell脚本详解-------循环语句wuile循环和until循环
开发一套高容错分布式系统
Hubei Mobile ZTE B860AV2.1_S905L_ flash firmware package
通关剑指 Offer——剑指 Offer II 010. 和为 k 的子数组
【LeetCode每日一题】——374.猜数字大小
xgboost模块param中的一些错误
谷歌开发者社区推荐:《Jetpack Compose 从入门到实战》新书上架,带你踏上 Compose 开发之旅~
The use of QCompleter for Qt auto-completion