大家好,欢迎来到IT知识分享网。
原题
挂个链接CodeForces
题目大意:详情参见洛谷CF949D
洛谷这题的翻译还真的不错。
Solution
分析:
很显然的,题目明显告诉我们,要求最大值的最小值,也就是最小化最大值,所以我们考虑二分答案.
但是这题并不需要二分答案,贪心就可以过.
我们考虑如果我们可以满足一个房间那么现在就满足他一定不会让答案变差,这很显然吧…
然后我们考虑如果一边满足了,显然就只需要考虑另一边.
所以只需要对于一边搞,然后贪心的算答案就好了.
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<iostream> #include<queue> #include<algorithm> #define ll long long #define re register using namespace std; inline int gi(){ int sum=0,f=1;char ch=getchar(); while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();} return f*sum; } inline ll gl(){ ll sum=0,f=1;char ch=getchar(); while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();} return f*sum; } int n; ll a[],s[],d,b; int main(){ n=gi();d=gl();b=gl(); for(re int i=1;i<=n;i++)a[i]=gl(); for(re int i=1;i<=n;i++)s[i]=s[i-1]+a[i]; int cnt1=0,cnt2=0; for(re int i=1;i<=n/2;i++){ ll x=s[min(1ll*n,i*(d+1))]-1ll*cnt1*b; if(x>=b)cnt1++; x=s[n]-s[max(0ll,n-i*(d+1))]-1ll*cnt2*b; if(x>=b)cnt2++; } printf("%d\n",n/2-min(cnt1,cnt2)); return 0; }
转载于:https://www.cnblogs.com/cjgjh/p/9769479.html
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/147247.html