2019 GDUT Rating Contest II : A. Taming the Herd
题面:
A. Taming the Herd
Farmer John was sick and tired of the cows’ morning breakouts, and he decided enough was enough: it was time to get tough. He nailed to the barn wall a counter tracking the number of days since the last breakout. So if a breakout occurred in the morning, the counter would be 0 that day; if the most recent breakout was 3 days ago, the counter would read 3. Farmer John meticulously logged the counter every day.
The end of the year has come, and Farmer John is ready to do some accounting. The cows will pay, he says! But lo and behold, some entries of his log are missing!
The second line contains N space-separated integers. The ith integer is either −1, indicating that the log entry for day i is missing, or a non-negative integer ai (at most 100), indicating that on day i the counter was at ai.
题目描述:
题目分析:
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 int n, a[105]; 5 6 int main(){ 7 cin >> n; 8 for(int i = 1; i <= n; i++){ 9 cin >> a[i]; 10 } 11 12 if(a[1] != 0 && a[1] != -1){ 13 cout << -1 << endl; //最简单的不合法情况 14 return 0; 15 } 16 17 a[1] = 0; //这个不要漏 18 for(int i = n; i >= 1;){ 19 while(a[i] == -1 && i >= 1) i--; //写这种代码时一定要记得 "i >= 1" 这样的限制条件 20 if(i == 0) break; //遍历完 21 22 int t = a[i]; 23 while(t >= 0 && i >= 1){ 24 if(a[i] != t && a[i] != -1){ //推算出的不合法 25 cout << -1 << endl; 26 return 0; 27 } 28 a[i--] = t--; 29 } 30 } 31 32 int minn, cnt; 33 minn = cnt = 0; 34 for(int i = 1; i <= n; i++){ //简单的计数 35 if(a[i] == 0) minn++; 36 if(a[i] == -1) cnt++; 37 } 38 39 cout << minn << " " << minn+cnt << endl; 40 return 0; 41 }
转载于:https://www.cnblogs.com/happy-MEdge/p/10530860.html
2019 GDUT Rating Contest II : A. Taming the Herd相关推荐
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2020 GDUT Rating Contest II (Div. 2) A. Fence Planning
来源 codeforces 2020 GDUT Rating Contest II (Div. 2) CF链接 题目: Farmer John's N cows, conveniently numbe ...
- 2019 GDUT Rating Contest I : Problem H. Mixing Milk
题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2020 GDUT Rating Contest I (Div. 2) A.Cow Gymnastics
来源 codeforces 2020 GDUT Rating Contest I (Div. 2) 题目: A. Cow Gymnastics In order to improve their ph ...
- 2020 GDUT Rating Contest III (Div2)
2020 GDUT Rating Contest III (Div2) A Wormhole Sort 题意: 给出N个打乱顺序的数,和M条边(a,b,c)表示在a位置的数可以和在b位置的数交换,这条 ...
- 2020 GDUT Rating Contest III (Div. 2) B - Loan Repayment 题解
原题 题目大意 给出NNN,KKK,MMM,假定已经给了GGG加仑奶,定义N−GX\frac{N-G}{X}XN−G为YYY,YYY最小为MMM,在KKK天后至少给NNN加仑奶,求最大的XXX. 题 ...
- 2020 GDUT Rating Contest I A. Cow Gymnastics
A. Cow Gymnastics 链接 题目描述 有n头牛一起参加了k次比赛,给出k次比赛的排名,问共有几组牛满足 其中一头牛每次比赛都比另一头厉害. 题目分析 由于数据量比较小(1<=k&l ...
- 2020 GDUT Rating Contest I (Div. 2) A - Cow Gymnastics 题解
好吧--是时候补一下题解了 原题 题目大意 给出n只牛,k次排序,如果有一只牛一直比另外一只牛更前算作一对,输出一共有多少对. 题目分析 水题(数据规模小),一开始初始化全部都可以,然后一个个删去就行 ...
- 2020 GDUT Rating Contest III H. Photoshoot
H. Photoshoot 链接 题目描述 有n头牛,他们的序号从为1-n,现在他们按一定顺序排好,给出每对相邻的两头牛的序号之和,求出牛现在的序号. 题目分析 因为确定其中一头牛的序号,就可以得出所 ...
最新文章
- NDK断点无法调试Unable to detect application ABI's
- go读取最后一行_CPU缓存体系对Go程序的影响
- Win64 驱动内核编程-17. MINIFILTER(文件保护)
- hadoop yarn 获取日志_赵丽颖固然漂亮,可这份Hadoop核心教程也不差啊!
- idea maven创建java项目_新版本IntelliJ IDEA 构建maven,并用Maven创建一个web项目(图文教程)...
- 我最喜爱的九位历史人物 - 曹操(Space搬家)
- 高斯克吕格投影知识总结
- 朋友圈加粗字体数字_字体:新游黑体(游ゴシック)重大更新,精巧的日系字体~...
- 2022年信息系统管理工程师考试大纲
- oracle pmon andsmon,SMON and PMON
- 【eos系列】智能合约 私链激活 基本操作
- 判断一个数是否为质数(素数)
- 5.项目上线流程管理规范
- mysql用拼音显示字段名_MySQL汉字字段按拼音排序显示
- 基于银河麒麟 V10 系统安装和卸载 DM8 数据库
- 卡卡卡的wordpress
- 路由器和计算机的功能有何不同,网关和路由器的区别是什么 两者又有什么不同...
- linux提取最新修改文件下载,linux 解压修改jar包内容并重新打包jar
- 计算机图形学三(补充):重心坐标(barycentric coordinates)详解及其作用
- 不用找,你想要的概念车壁纸素材都在这里