zoukankan      html  css  js  c++  java
  • hdu 5802 Windows 10

    官方题解:

    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
    ",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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    945.使数组唯一的最小增量
    用两个栈实现队列
    MySQL的约束
    数据库的设计
    约束
    DQL查询
    数据库的基本概念
    SQL基础语法
    MySQL基础
    java的注解和反射
  • 原文地址:https://www.cnblogs.com/yu0111/p/5743313.html
Copyright © 2011-2022 走看看