zoukankan      html  css  js  c++  java
  • Gym 101194D Ice Cream Tower

    被一道数位DP折磨得欲仙欲死之后,再做这道题真是如同吃了ice cream一样舒畅啊

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define ms(arr,a) memset(arr,a,sizeof arr)
    #define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
    typedef long long ll;
    const int maxn=3e5+5;
    ll a[maxn],b[maxn];
    int n,k;
    bool ok(int m)
    {
        ms(b,0);
        int cnt=1;
        for(int i=1;i<=k;++i)
        for(int j=1;j<=m;++j)
        {
            if(cnt>n)return false;
            while(a[cnt]<2*b[j]){cnt++;if(cnt>n)return false;}
            b[j]=a[cnt++];
        }
        return true;
    }
    int main()
    {
        freopen("Input.txt","r",stdin);
        freopen("1.txt","w",stdout);
        int T;scanf("%d",&T);
        for(int Case=1;Case<=T;Case++)
        {
    	scanf("%d%d",&n,&k);
    	for(int i=1;i<=n;++i)scanf("%lld",a+i);
    	sort(a+1,a+n+1);
    	int l=0,m,r=n/k;
        while(l<r)
        {
            m=(l+r+1)/2;
            if(ok(m))l=m;
            else r=m-1;
        }
        printf("Case #%d: %d
    ",Case,l);//
        }
        //freopen("CON","w",stdout);
        //system("start Output.txt");
    }
    
  • 相关阅读:
    HTML5---offline application(application cache)
    apache asp.net
    长轮询
    comet ajax轮询
    bootstrap3
    weixin
    backbone csdn
    backbone case
    backbone showcase
    javascript performance
  • 原文地址:https://www.cnblogs.com/maoruimas/p/9597079.html
Copyright © 2011-2022 走看看