首页 > 其他 > 详细

ICL2019E

时间:2019-03-29 23:26:17      阅读:217      评论:0      收藏:0      [点我收藏+]

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

 

ICL2019E

原文:https://www.cnblogs.com/MXang/p/10624773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!