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 ... 
随机推荐
- ubuntu 12.04安装jdk 8
			转载:http://www.itnose.net/detail/6196130.html Ubuntu12.4安装jdk1.8 1.要安装的jdk,我把它拷在了共享文件夹里面. (用优盘拷也可以 ... 
- Shadow Map 实现极其细节
			这里不介绍算法原理,只说说在实现过程中遇到的问题,以及背后的原因.开发环境:opengl 2.0 glsl 1.0. 第一个问题:产生深度纹理. 在opengl中每一次离屏渲染需要向opengl提供 ... 
- Java 设计模式系列(十三)模板方法
			Java 设计模式系列(十三)模板方法 模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑.不同的子类可以以不同的 ... 
- mongo学习-固定集合
			一.创建固定集合 db.createCollection("guding",{"capped":true,"size":10,"m ... 
- ffmpeg只编译h264
			./configure --arch=arm --cross-prefix=arm-none-linux-gnueabi- --extra-ldflags=-static --target-os=li ... 
- UVa 1374 Power Calculus (IDA*或都打表)
			题意:给定一个数n,让你求从1至少要做多少次乘除才可以从 x 得到 xn. 析:首先这个是幂级的,次数不会很多,所以可以考虑IDA*算法,这个算法并不难,难在找乐观函数h(x), 这个题乐观函数可以是 ... 
- UVa 1606 Amphiphilic Carbon Molecules (扫描法+极角排序)
			题意:平面上有 n 个点,每个点不是黑的就是白的,现在要放一个隔板,把它们分成两部分,使得一侧的白点数加上另一侧的黑点数最多. 析:这个题很容易想到的就是暴力,不妨假设隔板至少经过两个点,即使不经过也 ... 
- LCD相关基础知识
			1.什么是LCD? (1)LCD(Liquid Crystal Display)俗称液晶.液晶是一种材料,液晶这种材料具有一种特点:可以在电信号的驱动下液晶分子进行旋转,旋转时会影响透光性, 因此我们 ... 
- js 中的 2 与 "2"
			case1: "15" * 2 结果:30 case2: 2 * "15" 结果:30 case3: "2" * "15" ... 
- linux每天一小步---alias命令详解
			1 命令功能 alias命令用来设置指令的别名,alias命令设置的别名只限于该次登陆操作,若要每次登入即自动设好别名,可在/etc/profile或自己的~/.bashrc中设定指令的别名. ... 
