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 ...
随机推荐
- Linq操作DataTable
IEnumerable<DataRow> q = from dr in dt.AsEnumerable() where dr.Field& ...
- ubuntu账户密码正确但是登录不进去系统
ubuntu12.04管理员账户登录不了桌面,只能客人会话登录 求助!!ubuntu12.04管理员账户登录不了桌面,只能客人会话登录. ctrl+alt+f1 ,切换到tty1,输入管理员帐号和密码 ...
- Mac 安装GCC
OS X上安装Homebrew和GCC的图文攻略 2016年08月31日 11:21:27 白马负金羁 阅读数:11380 标签: OS XGCCHomebrew 更多 个人分类: 应用技巧 版权 ...
- JSONResult引用某博客
http://www.cnblogs.com/JerryWang1991/archive/2013/03/08/2950457.html 最近开始用MVC做项目,在使用 JsonResult返回数据的 ...
- SNMP++ 编译记录
/************************************************************** 技术博客 http://www.cnblogs.com/itdef/ ...
- openstack网络管理命令
1.获取网络列表 [root@cc ~(keystone_admin)]# neutron net-list +--------------------------------------+----- ...
- malloc.c
glibc-2.14中的malloc.c源代码,供研究malloc和free实现使用: /* Malloc implementation for multiple threads without lo ...
- git 创建管理远程分支
1.远程分支就是本地分支push到服务器上的时候产生的.比如master就是一个最典型的远程分支(默认). 1 $: git push origin master 除了master之外,我们还可以 ...
- [转]Clean up after Visual Studio
本文转自:https://weblogs.asp.net/psheriff/clean-up-after-visual-studio As programmer’s we know that if w ...
- java try catch finally return执行
public static int testBasic(){ int i = 1; try{ i++; System.out.println("try block, i = "+i ...