• hdu-5802 Windows 10(贪心)


    题目链接:

    Windows 10

    Time Limit: 2000/1000 MS (Java/Others)  

      Memory Limit: 65536/65536 K (Java/Others)


    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
     
    题意:
    问从p到q的最短时间是多少?
     
    思路:
     
    看的别人的才知道怎么做,每次连续下降x次,一共下降2x-1的音量;每次下降到比q大或者比q小最接近q的数,为什么这样呢?
    假设有两次的都连续下降x次.那么可以连成一个x+1的的下降,所以前边连续下降的次数比后边大;
     
    AC代码:
     
    /************************************************
    ┆  ┏┓   ┏┓ ┆   
    ┆┏┛┻━━━┛┻┓ ┆
    ┆┃       ┃ ┆
    ┆┃   ━   ┃ ┆
    ┆┃ ┳┛ ┗┳ ┃ ┆
    ┆┃       ┃ ┆ 
    ┆┃   ┻   ┃ ┆
    ┆┗━┓    ┏━┛ ┆
    ┆  ┃    ┃  ┆      
    ┆  ┃    ┗━━━┓ ┆
    ┆  ┃  AC代马   ┣┓┆
    ┆  ┃           ┏┛┆
    ┆  ┗┓┓┏━┳┓┏┛ ┆
    ┆   ┃┫┫ ┃┫┫ ┆
    ┆   ┗┻┛ ┗┻┛ ┆      
    ************************************************ */ 
     
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    //#include <bits/stdc++.h>
    #include <stack>
    #include <map>
     
    using namespace std;
     
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
     
    typedef  long long LL;
     
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
     
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const LL inf=1e18;
    const int N=2e5+10;
    const int maxn=2e3+14;
    const double eps=1e-12;
    
    LL ans,f[40];
    void dfs(LL p,LL q,LL time,int num)
    {
        if(max(p,0LL)==q)
        {
            ans=min(ans,time);
            return ;
        }
        else if(max(p,0LL)<q)
        {
            LL temp=q-max(0LL,p);
            ans=min(ans,time+max(temp-num,0LL));
            return ;
        }
        int l=1;
        while(p-(f[l]-1)>q)l++;
        dfs(p-(f[l]-1),q,time+l,num);
        if(l>1)dfs(p-(f[l-1]-1),q,time+l,num+1);
    }
    
    inline void solve(LL p,LL q)
    {
        ans=inf;
        dfs(p,q,0,0);
        printf("%lld
    ",ans);
    }
    inline void Init()
    {
        f[0]=1;
        For(i,1,35)f[i]=f[i-1]*2;
    }
    int main()
    {
        int t;
        LL p,q;
        read(t);
        Init();
        while(t--)
        {
            read(p);read(q);
            solve(p,q);
        }
        return 0;
    }
    

      

  • 相关阅读:
    docker搭建ros-indigo-arm交叉编译环境
    ROS系统C++代码测试之gtest
    ROS系统python代码测试之rostest
    ROS(Robot Operating System)常用环境变量介绍
    【持续更新】 | OpenCV 学习笔记
    Mac + PyCharm 安装 Opencv3 + python2.7
    如何用Caffe训练自己的网络-探索与试验
    九度OJ-第5章-图论
    看周志华教授的一番话有感
    姿势估计实验-Realtime_Multi-Person_Pose_Estimation-CMU
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5746509.html
Copyright © 2020-2023  润新知