hdu 5802 Windows 10

來源:互聯網
上載者:User

標籤:

官方題解:

Windows 10

_您可能是正版Windows 10的受害者_ 直接貪心就好

比較直觀的看法是使勁往下降,然後升回來

或者使勁往下降然後停頓然後再使勁往下降。。。

於是就能將問題變成一個子問題,然後dfs就好

需要注意的是由於按up鍵也可以打斷連續向下的功效

所以應該記錄停頓了幾次,以後向上的時候用停頓補回來

 

/*by*/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;typedef long long LL;const LL N=500;const LL INF=0x3f3f3f3f;LL p,q;int main(){    LL T;    cin>>T;    while(T--) {        scanf("%lld%lld",&p,&q);        if(p<=q) {            printf("%lld\n",q-p);            continue;        }        LL ans=INF,down=1,s=0,st=0;/*s:操作次數;st:停頓的次數*/        while(p>=q){            p-=down;            down<<=1;            s++;            if(p<=q){                if(q-p<=st){/*向上操作次數可以被停頓的次數代替*/                    ans=min(ans,s+st);                    break;                }                LL tmp=max(q-max(p,(LL)0),st);/*音量大於0*/                ans=min(ans,tmp+s);                down>>=1;                p+=down;                down=1;                st++;                s--;            }        }        printf("%lld\n",ans);    }    return 0;}

 

hdu 5802 Windows 10

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.