加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

ICL2019E

发布时间:2020-12-14 04:35:36 所属栏目:大数据 来源:网络整理
导读:https://www.codechef.com/ICL2019/problems/ICL1906 ?两个整数,[0,1e5] 操作1是让两个数同时减1(只有都大于0的时候才可以用) 操作2可以让一个数乘2 问让两个数都变成0的最小操作次数? ? 直接贪心。能乘就乘。 1 #include bits/stdc++.h 2 using namespace

https://www.codechef.com/ICL2019/problems/ICL1906

?两个整数,[0,1e5]
操作1是让两个数同时减1(只有都大于0的时候才可以用)
操作2可以让一个数乘2
问让两个数都变成0的最小操作次数?
?
直接贪心。能乘就乘。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int t,x,y;
 4 int main(){
 5     ios::sync_with_stdio(false);
 6     cin>>t;
 7     while (t--){
 8         cin>>x>>y;
 9         if(x==0&&y==0){
10             cout<<0<<endl;
11             continue;
12         }
13         if(x==0||y==0){
14             cout<<-1<<endl;
15             continue;
16         }
17         if(x>y)swap(x,y);
18         int ans = 0;
19         while (x!=y){
20             if(x*2<=y){
21                 x*=2;
22                 ans++;
23             }else{
24                 y--,x--;
25                 ans++;
26             }
27         }
28         ans+=x;
29         cout<<ans<<endl;
30     }
31 }
View Code

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读