zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    Android与互联网的交互方式有三种
    Android 本地tomcat服务器接收处理手机上传的数据之案例演示
    Android 本地tomcat服务器接收处理手机上传的数据之环境搭建
    win7 查看当前java路径
    Android 使用tomcat搭建HTTP文件下载服务器
    Android 本地搭建Tomcat服务器供真机测试
    Android org.apache.http.*找不到
    Android IndicatorSeekBar
    Volley overview
    android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error(Sqlite code 14): Could not open database,(OS error
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5746509.html
Copyright © 2011-2022 走看看