P4090 [USACO17DEC]Greedy Gift Takers
题目链接
题意分析
首先 如果当前序列中一头奶牛拿不到礼物的话
那么他后面的奶牛也拿不到礼物
所以我们可以二分
由于可以操作无限次
所以我们对于当前\([1,mid)\)的奶牛按照\(c\)值排序之后
贪心的先放\(c\)中最小的奶牛
如果依然存在一头奶牛被放在\(mid\)之前
那么就无法使\(mid\)得到礼物
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<vector>
#include<ctime>
#define ll long long
#define inf 0x7fffffff
#define N 500008
#define IL inline
#define M 108611
#define D double
#define ull unsigned long long
#define R register
using namespace std;
template<typename T>IL void read(T &_)
{
T __=0,___=1;char ____=getchar();
while(!isdigit(____)) {if(____=='-') ___=0;____=getchar();}
while(isdigit(____)) {__=(__<<1)+(__<<3)+____-'0';____=getchar();}
_=___ ? __:-__;
}
/*-------------OI使我快乐-------------*/
int n,ans;
int num[M],tmp[M];
IL bool check(int mid)
{
if(mid==1) return 1;
for(R int i=1;i<mid;++i) tmp[i]=num[i];
sort(tmp+1,tmp+mid);
int now=n-mid;
for(R int i=1;i<mid;++i)
{
if(tmp[i]>now) return 0;
++now;
}
return 1;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n);
for(R int i=1;i<=n;++i) read(num[i]);
int le=1,ri=n;ans=-1;
while(le<=ri)
{
int mid=(le+ri)>>1;
if(check(mid)) le=mid+1,ans=mid;
else ri=mid-1;
}
printf("%d\n",n-ans);
// fclose(stdin);
// fclose(stdout);
return 0;
}
P4090 [USACO17DEC]Greedy Gift Takers的更多相关文章
- [USACO17DEC]Greedy Gift Takers
题目描述 Farmer John's nemesis, Farmer Nhoj, has NN cows (1 \leq N \leq 10^51≤N≤105 ), conveniently numb ...
- NC24083 [USACO 2017 Dec P]Greedy Gift Takers
NC24083 [USACO 2017 Dec P]Greedy Gift Takers 题目 题目描述 Farmer John's nemesis, Farmer Nhoj, has N cows ...
- [BZOJ5139][Usaco2017 Dec]Greedy Gift Takers 权值线段树
Description Farmer John's nemesis, Farmer Nhoj, has NN cows (1≤N≤10^5), conveniently numbered 1…N. T ...
- [USACO 2017DEC] Greedy Gift Takers
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5139 [算法] 二分答案 时间复杂度 : O(NlogN^2) [代码] #incl ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- 119 - Greedy Gift Givers
Greedy Gift Givers The Problem This problem involves determining, for a group of gift-giving frien ...
- USACO Section 1.1-2 Greedy Gift Givers
Greedy Gift Givers 贪婪的送礼者 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那 ...
- Section 1.1 Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends hasdecided to exchange gifts o ...
- 1.1.4 PROB Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
随机推荐
- 微信小程序-滑动视图注意事项
真的得吐槽下微信的开发文档,一点点都不详细的好吗. <!--垂直滚动,这里必须设置高度--> <scroll-view scroll-y="true" style ...
- Ckeditor 中粘贴图片
我们在ckeditor 中有上传图片,但是实际使用中这种手动上传图片方式并不是很方便,而是复制或者截图粘贴图片. 这里我们实现主要是获取对应的粘贴事件. CKEDITOR.instances[&quo ...
- 我读《大数据时代的IT架构设计》
架构设计是一门艺术,对架构的掌握要通过多看,多学,多交流,多积累,从实战架构上总能吸收到很好的营养,这边书虽然 (一).hadoop技术处理电信行业的上网日志 根据上网的url或未知url爬取内容,进 ...
- SOCKET句柄泄露带来的内存灾难
前些时候游戏莫名其妙出现大量内存泄露,我感到很诧异,当然一般情况下游戏的内存管理是极其严苛的,出现如此大量的内存泄露到底是怎么回事? 句柄滥用导致的内存泄露会多夸张呢,尤其SOCKET,在某些客户端系 ...
- BUG记忆
保留两位小数 <fmt:formatNumber value="${list.avgAssessment}" pattern="#.00#"/> ...
- KbmMW 4.40.00 正式版发布
经过快3个月的测试,kbmmw 4.40 正式版终于在圣诞节前发布了. We are happy to announce the availability of a new kbmMW release ...
- Core Graphics Layer Drawing
[Core Graphics Layer Drawing] CGLayer objects (CGLayerRef data type) allow your application to use l ...
- http://www.rabbitmq.com/
什么是RabbitMQ 官网http://www.rabbitmq.com/ 1.应用程序间健壮的消息发送 2.简单易用 3.可在所有主流操作系统运行 4.支持巨量的开发者平台 5.开源和商用双重支持 ...
- Vivado&ISE&Quartus II调用Modelsim级联仿真
博主一直致力寻找高效的工作方式,所以一直喜欢折腾软件,从刚开始只用软件IDE自带的编辑器,到Notepad++,再到后来的Vim,从用ISE14.7自带的Isim仿真,到发现更好的Modelsim,再 ...
- DW2.0
一.DW2.0从企业的角度,吸引企业的原因: 1.数据仓库基础设施的成本不再持续增长.在第一代数据仓库中,技术基础设施的成本是不断增长的,随着数据量的增长,基础设施的成本会以指数级增长.但是使用DW2 ...