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;
}
Codeforces Round #469 (Div. 2) F. Curfew的更多相关文章
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #469 (Div. 2)
Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
随机推荐
- 能用程序解决的问题绝不BB之租房篇章...
项目缘起于高德API+Python解决租房问题, 修修补补之后上线了58公寓高德搜房(全国版)http://woyaozufang.live:8080. 经过了多次代码优化.内容改版.新增房源等... ...
- Dota2一直 正在登录服务器的解决办法
然后:1: c:\Windows\System32\drivers\etc\ 2:双击hosts文件,用记事本方式打开3:复制以下并粘贴至以记事本方式打开的hosts最后面111.221.33.253 ...
- hugepages_settings.sh
#!/bin/bash## hugepages_settings.sh## Linux bash script to compute values for the# recommended HugeP ...
- 第一阶段·Linux运维基础-第2章·Linux系统目录结构介绍
01 变量与PS1 02 添加用户 03 关闭SELinux 04 关闭iptables 05 显示中文乱码排查过程 06 总结 07 目录结构课程内容 08 Linux目录结构特点 09 Linux ...
- IntelliJ IDEA 新建项目
一 新建一个Java项目 二 新建一个Web项目 三 新建一个Maven项目 四 web.xml常见版本 <?xml version="1.0" encoding=" ...
- (查找函数+atoi)判断与(注册函数+strcmp函数)判断两种方法
loadrunner中接口判断的2中方法 如下: 1. ●查找函数web_reg_find() ● atoi():将字符串转换为整型值 作比较 > 0 Action() { //检查点函 ...
- hdu刷题1
1002 大数加法 #include<iostream> #include<cstring> using namespace std; int main() { ],b[]; ...
- 孵化器使用Office365的场景及收益
- cenos环境变量配置
Beego环境搭建和bee工具安装使用,以Windows环境为例. 首先,下载并安装好GO并配置好GOROOT和GOPATH环境变量(如果您是用msi包安装的go,那么这些环境变量已经设置好了).并在 ...
- struts2 result type属性说明
首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-type name="chain" ...