题目链接

题意分析

首先 如果当前序列中一头奶牛拿不到礼物的话

那么他后面的奶牛也拿不到礼物

所以我们可以二分

由于可以操作无限次

所以我们对于当前\([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的更多相关文章

  1. [USACO17DEC]Greedy Gift Takers

    题目描述 Farmer John's nemesis, Farmer Nhoj, has NN cows (1 \leq N \leq 10^51≤N≤105 ), conveniently numb ...

  2. 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 ...

  3. [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 ...

  4. [USACO 2017DEC] Greedy Gift Takers

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5139 [算法] 二分答案 时间复杂度 : O(NlogN^2) [代码] #incl ...

  5. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  6. 119 - Greedy Gift Givers

     Greedy Gift Givers  The Problem This problem involves determining, for a group of gift-giving frien ...

  7. USACO Section 1.1-2 Greedy Gift Givers

    Greedy Gift Givers 贪婪的送礼者 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那 ...

  8. Section 1.1 Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends hasdecided to exchange gifts o ...

  9. 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 ...

随机推荐

  1. qemu模拟器下编译运行基于riscv指令集的Linux操作系统

      基本原理: 在物理服务器Ubuntu14.04上安装qemu模拟器,模拟器中运行基于riscv指令集编译的linux镜像文件. 用到的工具包括: riscv-qemu(模拟器,可以模拟运行risc ...

  2. for 续1

    --------siwuxie095                 /f 是四个参数中最复杂的一个,非常强大,不过其复杂性 令人望而生畏     /f 用途: 能够对字符串进行操作,也能够对命令的返 ...

  3. Shiro01 功能点框图、架构图、身份认证逻辑、身份认证代码实现

    基本功能点 功能点框图 功能点说明 1.Authentication:身份认证/登录,验证用户是不是拥有相应的身份: 2.Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个 ...

  4. [GO]go context的deadline方法

    package main import ( "time" "context" "fmt" ) func main() { d := time ...

  5. [operator]ubuntu + sublime + anaconda 自动补全、指定python版本

    ubuntu .sublime.anaconda都安装好之后,首先要解决的就是自动补全问题 Perference---->Browes Packages --->新建一个Python的文件 ...

  6. [C#]安装WindowsService的关键步骤

    使用.Net编写好了WindowsService以后,不安装到系统里就没有任何作用. [添加Installer] 在服务的设计器画面,属性页面里,选择[Add Installer]链接. 如此便会生成 ...

  7. CentOS6.5中使用 iperf 检测主机间网络带宽

    安装方式 # yum install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm# yum inst ...

  8. css 颜色渐变 兼容性

    参考文献:http://caibaojian.com/css3-background-gradient.html    https://www.cnblogs.com/xzzzys/p/7495725 ...

  9. ffmpeg学习(一)——在window7下编译ffmpeg

    FFmpeg是一个开源免费跨平台的视频和音频流项目,它提供了录制.转换以及流化音视频的完整解决方案.本文作者将尝试使用该库实现一个可适应复杂网络环境的, 支持标准rtsp协议的流媒体服务器.由于Vis ...

  10. Solr相似度算法四:IBSimilarity

    Information based:它与Diveragence from randomness模型非常相似.与DFR相似度模型类似,据说该模型也适用于自然语言类的文本.