Farmer John's nemesis, Farmer Nhoj, has N cows (1≤N≤105 ), conveniently numbered 1...N .They have unexpectedly turned up at Farmer John's farm, so the unfailingly polite Farmer John is attempting to give them gifts.

To this end, Farmer John has brought out his infinite supply of gifts, and Nhoj's cows have queued up in front of him, with cow t the head of the queue and cow at the tail. Farmer John was expecting that at every timestep, the cow at the head of the queue would take a gift from Farmer John and go to the tail of the queue. However, he has just realized that Nhoj's cows are not that polite! After receiving her gift, each cow may not go to the tail of the queue, but rather may cut some number of cows at the tail, and insert herself in front of them. Specifically, cow will always cut exactly Ci cows (0≤Ci≤N-1).

Farmer John knows that some cows might receive multiple gifts; as he has an infinite supply, this does not worry him. But he is worried that some cows might become unhappy if they do not get any gifts.Help Farmer John find the number of cows who never receive any gifts, no matter how many gifts are handed out.

INPUT FORMAT (file greedy.in):

The first line contains a single integer, N.

The second line contains N space-separated integers C1,C2,C3...CN.

OUTPUT FORMAT (file greedy.out):

Please output the number of cows who cannot receive any gifts.

SAMPLE INPUT:

3

1 2 0

SAMPLE OUTPUT:

1

翻译:

农场主Nhoj是农场主John的死对头,他有N头奶牛(1≤ N ≤ 105),为了记录方便,给奶牛们从1 … N的顺序编了号。这些奶牛很意外的出现了在John的农场里,所以这位彬彬有礼的农场主John打算给这些奶牛送点礼物。

为此,农夫John准备了无限量的礼物给那些奶牛,而Nhoj的奶牛们也已经在他的面前排好队了,奶牛1排在队伍的最前面,奶牛N排在队伍的最后。农夫John希望这些奶牛可以按顺序拿好礼物,然后再按顺序从队伍的前头排到队伍的最后。然而,他刚刚才意识到Nhoj的奶牛们并不会按照他想的那样行动。而是在拿到礼物后,每头牛都不一定会排到队伍的最后,甚至可能在队伍的后方插队。具体点说就是奶牛i总是会插在Ci头牛的前边(0 ≤ ci≤ N-1)。

农夫John并不担心有些牛可能会收到多份的礼物,因为他准备了无限多的礼物,但是,他担心有些牛可能会因为没有收到任何礼物而不开心。

请帮助农民John计算一下在送出的礼物数量没有限制的情况下,收不到任何礼物的牛的数量。

输入格式(file greedy.in):

第一行填写一个整数N。

第二行填写N个用空格分开的整数c1,c2, … , cN

输出格式(file greedy.out):

请输出不能收到任何礼物的牛的数量。

#include<bits/stdc++.h>
#define ll long long
#define mode 1000000007
using namespace std;
int x[100010],y[100010];
bool cmp(int a,int b)
{return a>b;
}
int check(int a)
{int b=a;for(int i=1; i<b; i++){y[i]=x[i];}sort(y+1,y+b,cmp);for(int i=1; i<b; ++i){if(y[i]<a)return false;a--;}return true;
}
int main()
{int n;scanf("%d",&n);for(int i=1; i<=n; ++i){scanf("%d",&x[i]);x[i]=n-x[i];}int l=1,r=n,mid,ans=1;while(l<=r){mid=(l+r)/2;if(check(mid)){ans=mid;l=mid+1;}elser=mid-1;}cout<<n-ans<<endl;return 0;
}

https://www.sohu.com/a/211375775_641382

https://www.cnblogs.com/JYYHH/p/8401237.html

转载于:https://www.cnblogs.com/qksy/p/8433931.html

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

  3. P4090 [USACO17DEC]Greedy Gift Takers

    题目链接 题意分析 首先 如果当前序列中一头奶牛拿不到礼物的话 那么他后面的奶牛也拿不到礼物 所以我们可以二分 由于可以操作无限次 所以我们对于当前\([1,mid)\)的奶牛按照\(c\)值排序之后 ...

  4. USACO 2017 December Contest Platinum T3: Greedy Gift Takers

    题目大意 有 N(1≤N≤1e5)头牛按顺序排成一列,编号从 1 到 N,1 号牛在队头,N 号牛在队尾. 每次位于队头的牛 i 拿到一个礼物,然后插入到从队尾数ci​头牛之前的位置..举个栗子: 初 ...

  5. bzoj5139 [Usaco2017 Dec]Greedy Gift Takers

    http://www.elijahqi.win/2018/02/06/bzoj5139/ 我这种智商低下曾经还不努力的人如果现在不努力,怕是没有大学上了 [题意] n个奶牛排成一排,顺次编号为1到n ...

  6. bzoj5139 [Usaco2017 Dec]Greedy Gift Takers(二分答案+模拟)

    首先我们发现如果第x头牛不能拿到礼物,则x之后的所有牛也不能拿到礼物.因此我们可以二分来找到这第一头不能拿到礼物的牛.满足什么条件的牛不能拿到礼物呢?我们预处理出每头牛拿到礼物之后会出现在哪里,如果在 ...

  7. [USACO 2017DEC] Greedy Gift Takers

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

  8. USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers

    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...

  9. Greedy Gift Givers

    原题地址 Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange g ...

最新文章

  1. android炫酷的自定义view,Android自定义View实现炫酷进度条
  2. .NetCore~框架版本号不同引起dotnet不能run它
  3. python virtualenv用法
  4. Centos6.5环境中安装vsftp服务
  5. 牛客16500 珠心算测试
  6. uniCloud免费云存储图床源码
  7. 中兴新支点国产操作系统新版本越来越好用了
  8. 易班打卡——自动填写健康日报
  9. C#模拟IIS服务器(一)
  10. WordPress企业主题:企业一号
  11. vue项目运行出现66% buil 98% after emitting CopyPlugin
  12. App Store风靡!当下热门应用商店简析
  13. uniapp插件市场-涂图视频编辑-美妆-剪辑-微整形原生sdk插件发布-优雅草科技
  14. cacheable 表达式,多个方法参数的@Cacheable键
  15. 对使用字符指针变量和字符数组的讨论
  16. 分享一款多线程磁力搜索工具-聚磁帮
  17. 牛客网数据库SQL实战25—— 获取员工其当前的薪水比其manager当前薪水还高的相关信息
  18. 关于 git 的用法
  19. (免费分享)基于javaweb,ssm旅游信息系统
  20. 陌陌推出“树莓”APP入局种草赛道,如何避免碰瓷“小红薯”?

热门文章

  1. 全球及中国生物识别技术产业应用趋势及投资风险分析报告2021-2027年
  2. 自学渗透第四天--中国菜刀
  3. 多玩我的世界盒子电脑版 免费官方版
  4. 小提琴和钢琴一起学行吗_小提琴和钢琴存在一种羁绊
  5. MicroNet论文复现:用极低的FLOPs改进图像识别
  6. 2022年全球市场菱镁矿和水镁石总体规模、主要生产商、主要地区、产品和应用细分研究报告
  7. 微课在中职计算机基础中的应用,微课在中职计算机基础教学中的应用探析
  8. XiaoHu是什么?(介绍帖)
  9. skywalking实战--agent异常日志监控
  10. 群晖传文件到服务器,文件上传到群晖服务器