P4379 [USACO18OPEN]Lemonade Line
最差情况就是耐性最好的牛都在前面.
照此贪心, 排个序以后看从哪个牛开始耐不住就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相关推荐
- 洛谷 P4379 [USACO18OPEN]Lemonade Line
P4379 [USACO18OPEN]Lemonade Line 题目描述 这是农场上一个炎热的夏日,Farmer John要给他的 NN 头奶牛发柠檬汽水了!所有的 NN 头奶牛(方便起见,编号为 ...
- USACO2018 OPEN TEST - Silver
USACO2018 OPEN TEST - Silver 1. Lemonade Line 题目描述 这是农场上一个炎热的夏日,Farmer John要给他的 NNN 头奶牛发柠檬汽水了!所有的 NN ...
- GDUT 寒假排位赛三
[题目链接:]http://codeforces.com/group/NVaJtLaLjS/contest/238202 感想 emmmm,这套题有个特点,代码量小的考思维,而那些一眼看过去思路就有了 ...
- 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 ...
- Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView
今天创建了一个 demo ,然后就是复制RecyclerView 过去, 到最后完成运行的时候发现 系统奔溃了, 然后 提示 Binary XML file line #8: Error inflat ...
- 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 这个问题自己大致在 ...
- 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 ...
- OpenCV Hough Line变换
API Probabilistic Hough Line变换(概率霍夫线变换)vector<Vec4i> lines; HoughLinesP(dst, lines, 1, CV_PI/1 ...
- Laravel Predis Error while reading line from the server.
问题 Laravel说明文档中的 Redis 发布与订阅案例,命令行运行php artisan redis:subscribe 到60s自动断开并报错 [Predis\Connection\Conne ...
最新文章
- 【周末阅读】工业互联网的发展历程及实现路径
- VMware虚拟机相关文件问题
- 数开头的成语有哪些_艺术留学文书申请过程中应避开哪些雷区?ACG艺术留学
- Core Linux折腾(二)
- LSMW批处理使用方法(04)_步骤3上
- 小TIPS:合拼gridview的header
- unix dos mac 文件格式不同导致问题
- HDUOJ---The number of divisors(约数) about Humble Numbers
- 好婚姻必定是灵魂佳偶
- java批量查询导致堆内存不足,带有嵌套聚合的Elasticsearch查询导致内存不足
- 使用SQL查询多个表的笛卡尔积
- matlab中的hold on/off、grid on/off 命令使用方法
- 木兰开源许可证:开源社如是说
- 感谢米老师,感谢提高班,做个骄傲的自己
- mysql存密码_存储用户ID和密码到mysql数据库的方法
- Quartus-建立新工程
- Gate仿真配置安装--Linux系统
- 彻底解决汉诺塔问题——递归算法
- 【Spring Cloud Alibaba】Gateway 服务网关
- skyline v6 三维学习软件