zoukankan      html  css  js  c++  java
  • hdu5491 the next 贪心水题

    补了下去年网络赛的题。。。很无语的感觉。。。。

    这道签到去年做了4个小时,WA了十次。。。。后来还是队友过的,赛后由于网络赛打得太惨,也没敢去补题。。。

    现在再来看这题,,,好简单。。。。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    #define key_val ch[ch[rt[i]][1]][0]
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=1000100;
    const int INF=1e9+10;
    
    ll d,s1,s2;
    
    int cnt1(ll n)
    {
        int res=0;
        while(n){
            res+=n%2;
            n>>=1;
        }
        return res;
    }
    
    ll solve(ll d)
    {
        int one=cnt1(d);
        if(s1<=one&&one<=s2) return d;
        if(one<s1){
            int cnt=one;
            for(int i=0;i<s1;i++){
                if(cnt>=s1) break;
                if(d&(1<<i)) continue;
                else d|=(1<<i),cnt++;
            }
            return d;
        }
        else{
            for(int i=0;;i++){
                if(d&(1<<i)) return solve(d+(1<<i));
            }
        }
    }
    
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("in.txt","r",stdin);
        #endif
        int casen=1;
        int T;cin>>T;
        while(T--){
            scanf("%I64d%I64d%I64d",&d,&s1,&s2);
            d++;
            printf("Case #%d: %I64d
    ",casen++,solve(d));
        }
        return 0;
    }
    View Code
    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    各种集群服务
    cdn
    网页请求的完整过程
    html
    ajax异步请求技术
    浅谈前端渲染与后端渲染的区别
    html与php
    Ubuntu安装anaconda3
    win10安装Ubuntu系统
    删除排序数组中的重复项
  • 原文地址:https://www.cnblogs.com/--560/p/5211032.html
Copyright © 2011-2022 走看看