最差情况就是耐性最好的牛都在前面.
照此贪心, 排个序以后看从哪个牛开始耐不住就OK
唯一要注意的就是所有牛的耐性都大于\(N\)的情况.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 20;
inline int read()
{int x = 0; char ch = getchar();while(!isdigit(ch)) ch = getchar();while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();return x;
}int N;
int a[MAXN];int main()
{cin>>N;for(int i = 1; i <= N; i++) a[i] = read();sort(a + 1, a + N + 1, greater<int>());int ans = N;for(int i = 1; i <= N; i++) if(a[i] < i - 1) {ans = i - 1; break;}cout<<ans<<endl;return 0;
}

转载于:https://www.cnblogs.com/wsmrxc/p/9458704.html

P4379 [USACO18OPEN]Lemonade Line相关推荐

  1. 洛谷 P4379 [USACO18OPEN]Lemonade Line

    P4379 [USACO18OPEN]Lemonade Line 题目描述 这是农场上一个炎热的夏日,Farmer John要给他的 NN 头奶牛发柠檬汽水了!所有的 NN 头奶牛(方便起见,编号为  ...

  2. USACO2018 OPEN TEST - Silver

    USACO2018 OPEN TEST - Silver 1. Lemonade Line 题目描述 这是农场上一个炎热的夏日,Farmer John要给他的 NNN 头奶牛发柠檬汽水了!所有的 NN ...

  3. GDUT 寒假排位赛三

    [题目链接:]http://codeforces.com/group/NVaJtLaLjS/contest/238202 感想 emmmm,这套题有个特点,代码量小的考思维,而那些一眼看过去思路就有了 ...

  4. SyntaxError: Non-ASCII character ‘\xe5‘ in file(xxlrt_1.py) on line 7, but no encoding declared;

    具体报错如下: SyntaxError: Non-ASCII character '\xe5' in file /home/hly/work/python/work/xlrt_1.py on line ...

  5. Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView

    今天创建了一个 demo ,然后就是复制RecyclerView 过去, 到最后完成运行的时候发现 系统奔溃了, 然后 提示 Binary XML file line #8: Error inflat ...

  6. Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin

    Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin 这个问题自己大致在 ...

  7. android.view.InflateException: Binary XML file line #7: Binary XML file line #7

    错误如下 11-21 08:19:44.040 3608-3608/com.leon.oldrecyclerview E/AndroidRuntime: FATAL EXCEPTION: main   ...

  8. OpenCV Hough Line变换

    API Probabilistic Hough Line变换(概率霍夫线变换)vector<Vec4i> lines; HoughLinesP(dst, lines, 1, CV_PI/1 ...

  9. Laravel Predis Error while reading line from the server.

    问题 Laravel说明文档中的 Redis 发布与订阅案例,命令行运行php artisan redis:subscribe 到60s自动断开并报错 [Predis\Connection\Conne ...

最新文章

  1. 【周末阅读】工业互联网的发展历程及实现路径
  2. VMware虚拟机相关文件问题
  3. 数开头的成语有哪些_艺术留学文书申请过程中应避开哪些雷区?ACG艺术留学
  4. Core Linux折腾(二)
  5. LSMW批处理使用方法(04)_步骤3上
  6. 小TIPS:合拼gridview的header
  7. unix dos mac 文件格式不同导致问题
  8. HDUOJ---The number of divisors(约数) about Humble Numbers
  9. 好婚姻必定是灵魂佳偶
  10. java批量查询导致堆内存不足,带有嵌套聚合的Elasticsearch查询导致内存不足
  11. 使用SQL查询多个表的笛卡尔积
  12. matlab中的hold on/off、grid on/off 命令使用方法
  13. 木兰开源许可证:开源社如是说
  14. 感谢米老师,感谢提高班,做个骄傲的自己
  15. mysql存密码_存储用户ID和密码到mysql数据库的方法
  16. Quartus-建立新工程
  17. Gate仿真配置安装--Linux系统
  18. 彻底解决汉诺塔问题——递归算法
  19. 【Spring Cloud Alibaba】Gateway 服务网关
  20. skyline v6 三维学习软件

热门文章

  1. scarpy-爬取链家所有成交数据
  2. ASIC设计中的分频时钟
  3. office的加载项作用
  4. Word中Endnote加载项不见处理办法
  5. 1253号C语言程序设计试题,2016年1月试卷号1253C语言程序设计A.pdf
  6. mysql备份导出数据库结构_MySql数据库导出完整版(导出数据库,导出表,导出数据库结构)详解...
  7. 跨考计算机408的学习心得技巧分享
  8. TL431和PC817在开关电源中的工作详解
  9. VirtualBox虚拟机的网卡地址重复导致的问题
  10. ldd显示可执行模块的dependenc