Gym 101194D Ice Cream Tower
生活随笔
收集整理的這篇文章主要介紹了
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\n",Case,l);//}//freopen("CON","w",stdout);//system("start Output.txt"); }轉載于:https://www.cnblogs.com/maoruimas/p/9597079.html
總結
以上是生活随笔為你收集整理的Gym 101194D Ice Cream Tower的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【C#】VS2017 winform 打
- 下一篇: mac下shell给文件名批量加前缀