• hdu5802 Windows 10 贪心


    Windows 10

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2096    Accepted Submission(s): 630


    Problem Description
    Long long ago, there was an old monk living on the top of a mountain. Recently, our old monk found the operating system of his computer was updating to windows 10 automatically and he even can't just stop it !!
    With a peaceful heart, the old monk gradually accepted this reality because his favorite comic LoveLive doesn't depend on the OS. Today, like the past day, he opens bilibili and wants to watch it again. But he observes that the voice of his computer can be represented as dB and always be integer.
    Because he is old, he always needs 1 second to press a button. He found that if he wants to take up the voice, he only can add 1 dB in each second by pressing the up button. But when he wants to take down the voice, he can press the down button, and if the last second he presses the down button and the voice decrease x dB, then in this second, it will decrease 2 * x dB. But if the last second he chooses to have a rest or press the up button, in this second he can only decrease the voice by 1 dB.
    Now, he wonders the minimal seconds he should take to adjust the voice from p dB to q dB. Please be careful, because of some strange reasons, the voice of his computer can larger than any dB but can't be less than 0 dB.
     
    Input
    First line contains a number T (1T300000),cases number.
    Next T line,each line contains two numbers p and q (0p,q109)
     
    Output
    The minimal seconds he should take
     
    Sample Input
    2 1 5 7 3
     
    Sample Output
    4 4
     
    Author
    UESTC
     
    Source
    /**
    题目:hdu5802 Windows 10
    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5802
    题意:调节音量p到q,上升音量每秒只能上升1,下降音量每秒为2*x,x为上一次下降的音量,如果下降时休息或者上升音量则x置为1,音量最低为0
    题意有问题:题目说p不能降为负数。但是如果p-x<0;那么可以把p-x<0的结果都看做p-x==0;
    
    思路:贪心的去选,每次下降到终点上的最近一点,或者终点下的一点,取得一个最小值就好。
    
    */
    
    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    const int mod=1e9+7;
    const int maxn=1e6+5;
    const double eps = 1e-12;
    LL dfs(LL p,LL q,LL delay)
    {
        LL x = 1;
        LL cnt = 0;
        while(p-x>=q){
            cnt++;
            p = p-x;
            x = x*2;
        }
        if(p==q) return cnt;
        return min(max(0LL,q-max(0LL,(p-x))-delay)+cnt+1,dfs(p,q,delay+1)+cnt+1);
    
    }
    int main()
    {
        int T;
        LL p, q;
        cin>>T;
        while(T--)
        {
            scanf("%lld%lld",&p,&q);
            if(p<q){
                printf("%lld
    ",q-p);
            }else
            {
                printf("%lld
    ",dfs(p,q,0));
            }
        }
    
        return 0;
    }
  • 相关阅读:
    jmeter循环控制器
    SQL语句
    Linux防火墙常用命令
    利用cookie,实现刷新页面跳转,左侧菜单点击后状态保持不变。
    JQUERY动态生成当前年份的前5年以及后 2年
    (个人累积,分享)制作iconfont并转化图标代码使用
    如果一张要显示的图片穿插着两个路径该怎么解决?
    上传图片后台写法
    分析器错误消息:未能加载类型“XXXXXXX”
    尝试加载应用时出现了以下错误
  • 原文地址:https://www.cnblogs.com/xiaochaoqun/p/6889023.html
Copyright © 2020-2023  润新知