Codeforces Round #469 (Div. 2) F. Curfew

贪心

题目大意,有2个宿管分别从1和n开始检查房间,记录人数不为n的房间个数,然后锁住房间。

没有被锁的房间中的学生可以选择藏在床底,留在原地,或者转移(最远转移d个房间)

 

然后抄了网上大神的代码。

首先,如果可以转移的人数够,能使外面的满足房间b人的条件,就尽量满足。如果人数不够,就全部向内进行转移。

所有的人都可以不断向内转移,所以最优的一种情况一定不会发现某个房间人数多了。。(除了最靠内的房间)

然后保存一个区间和,一个房间一个房间进行判断。

这个思路好妙啊

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
       LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 200000 + 10;
LL n,d,b;
LL s[maxn];
LL ans1,ans2;

LL query(LL l,LL r)
{
    if(r>n) r=n;
    if(l<1) l=1;
    return s[r]-s[l-1];
}

void build()
{
    n=read(); d=read(); b=read();
    for(int i=1,a;i<=n;i++) 
    {
        a=read();
        s[i]=a+s[i-1];    
    }
}

void solve()
{
    for(int i=1;i<=n/2;i++) 
    {
        if(query(1,i+i*d)>=(ans1+1)*b) ans1++;  
        if(query(n-i+1-i*d,n)>=(ans2+1)*b) ans2++; 
    }
    cout<<max(n/2-ans1,n/2-ans2)<<'\n';
}

int main() 
{
    build();
    solve();
    
    return 0;
}
posted @ 2018-03-29 11:44  invoid  阅读(99)  评论(0编辑  收藏  举报