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 ...
随机推荐
- java中的装箱及拆箱
java中存在8中基本的数据类型,每一种数据类型都有包装类型. 包装类型:每一个基本的数据类型都会------对应一个包装类型. boolean------------------>Boolea ...
- KafkaConsumer 简析
使用方式 创建一个 KafkaConsumer 对象订阅主题并开始接收消息: Properties properties = new Properties(); properties.setPrope ...
- codeforces - 15C Industrial Nim(位运算+尼姆博弈)
C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- codeforces 10C Digital Root(非原创)
Not long ago Billy came across such a problem, where there were given three natural numbers A, B and ...
- css effect all in one
css effect all in one CSS 特效汇总 / 前端特效汇总 图片滑动对比 https://www.fika.io/ https://chrome.google.com/websto ...
- WiFi & QR Code
WiFi & QR Code https://github.com/bndw/wifi-card https://wifi.dev.bdw.to/ 扫码登录 WIFI:T:WPA;S:free ...
- Flutetr flutter_downloader 1.3.1
flutter_downloader 此库更新极慢,所以问题及多,可以看文档 安装 dependencies: flutter_downloader: ^1.3.1 配置 Java: // MyApp ...
- 为什么说USDN是一种应用型稳定币?
USDN是由NGK Global出品的一种新型稳定币系统,里面是涵盖了包括货币供需.Bancor.抵押借贷等在内的一整套算法.该稳定币构想一经提出,便在社区引发了不小的热度. 官方对于USDN的定位是 ...
- 人物传记:Mila Fletcher:如何勤于思考抓住关键?
Mila Fletcher于2007年毕业于耶鲁大学,她是一名真正意义上的法学博士,在校期间获得了马歇尔奖学金,毕业后曾在美国多家知名律师事务所任职,目前就职于星盟全球投资公司,专注于帮助公司和客户提 ...
- 前端监控SDK开发分享
目录 前言 收集哪些数据 性能 错误 辅助信息 小结 客户端SDK(探针)相关原理和API Web 微信小程序 编写测试用例 单元测试 流程测试 提供Web环境的方式 Mock Web API的方式 ...