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 }
2019 GDUT Rating Contest II : A. Taming the Herd的更多相关文章
- 2019 GDUT Rating Contest II : Problem F. Teleportation
题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...
- 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 ...
- 2019 GDUT Rating Contest II : Problem C. Rest Stops
题面: C. Rest Stops Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest II : Problem B. Hoofball
题面: 传送门 B. Hoofball Input file: standard input Output file: standard output Time limit: 5 second Memor ...
- 2019 GDUT Rating Contest III : Problem D. Lemonade Line
题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...
- 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 ...
- 2019 GDUT Rating Contest I : Problem A. The Bucket List
题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem G. Back and Forth
题面: G. Back and Forth Input file: standard input Output file: standard output Time limit: 1 second Mem ...
- 2019 GDUT Rating Contest III : Problem E. Family Tree
题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...
随机推荐
- 爬虫入门四 re
title: 爬虫入门四 re date: 2020-03-14 16:49:00 categories: python tags: crawler 正则表达式与re库 1 正则表达式简介 编译原理学 ...
- sdut2879 枚举起点DP
这个题和乌龟棋之类的DP差不多要学会缩减状态 就是,,我们只需枚举当前这个人是谁,选什么颜色,A用了多少,B用了多少 C用了多少我们就不用枚举了,知道选了多少人,A,B用了多少,你还不知C用了多少么, ...
- codevs1039整数的k划分-思考如何去重复
题目描述将整数n分成k份,且每份不能为空,任意两种划分方案不能相同(不考虑顺序).例如:n=7,k=3,下面三种划分方案被认为是相同的.1 1 51 5 15 1 1问有多少种不同的分法.输入描述输入 ...
- 如何用 js 实现一个 apply 函数
如何用 js 实现一个 apply 函数 原理 实现方式 总结 refs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ...
- git cli all in one
git cli all in one https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud git create ...
- UI Design & App & Free Icons
UI Design & App & Free Icons icons8 https://icons8.com https://icons8.com/ouch Ouch可以帮助那些不进行 ...
- mobile chart & f2
mobile chart & f2 https://www.yuque.com/antv/f2/getting-started https://antv.alipay.com/zh-cn/f2 ...
- GitHub & JavaScript & Trending
GitHub & JavaScript & Trending Trending JavaScript repositories on GitHub this week https:// ...
- 为什么 Python 的 f-string 可以连接字符串与数字?
本文出自"Python为什么"系列,归档在 Github 上:https://github.com/chinesehuazhou/python-whydo 毫无疑问,Python ...
- HarmonyOS三方件开发指南(13)-SwipeLayout侧滑删除
鸿蒙入门指南,小白速来!0基础学习路线分享,高效学习方法,重点答疑解惑--->[课程入口] 目录:1. SwipeLayout组件功能介绍2. SwipeLayout使用方法3. SwipeLa ...