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 ...
随机推荐
- 4.安装fluentd用于收集集群内部应用日志
作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-06-13 11:02:14 星期四 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...
- codeforces 1010 C. Border【exgcd】
题目链接:戳这里 学习博客:戳这里 题意:给n种数,n种数取任意个任意组合相加为sum,求sum%k有哪些值. 解题思路: 由exgcd可知(具体用到的是贝祖定理),ax + by = c,满足gcd ...
- JBoss 5.x和6.x 反序列化漏洞(CVE-2017-12149)
0x01 漏洞简介 该漏洞为 Java反序列化错误类型,存在于 Jboss 的 HttpInvoker 组件中的 ReadOnlyAccessFilter过滤器中.该过滤器在没有进行任何安全检查的情况 ...
- Spring应用上下文生命周期
Spring应用上下文生命周期整体分成四个阶段 ConfigurableApplicationContext#refresh,加载或者刷新持久化配置 ConfigurableApplicationCo ...
- Taro 3.x in Action
Taro 3.x in Action React, 小程序 https://taro-docs.jd.com/taro/docs/README Taro Next 跨端, 跨框架 Taro 是一个开放 ...
- 同城速递 & 同城跑腿 & 竞品分析
同城速递 & 同城跑腿 & 竞品分析 toC / toB 闪送 https://www.ishansong.com/ https://www.tianyancha.com/compan ...
- moment.js 时间格式转换
moment.js 时间格式转换 moment.js 时间转化 bug 格式错误 bug 02:00 => 14:00 format HH 与 hh HH === 24 小时制 hh === 1 ...
- 「NGK每日快讯」12.15日NGK公链第42期官方快讯!
- 为什么NGK推出的DEFI项目这么火热?
进入到2020年的下半年,DeFi的锁仓量基本上是以日破新高的态势,不断的成为一个独角兽.DeFi逐渐形成一个独角兽的同时,也在不断的给区块链生态赋能,源源不断进行金融价值输送.所以加密货币体量的不断 ...
- SpringBoot + Security学习笔记
SpringSecurity学习笔记 本以为是总结,最后写成了笔记,所以还是需要更加的努力啊. 开始的时候看了一遍官方文档,然后只看懂了加密器. 然后又学了一个尚硅谷的视频,虽然这个教程是在讲一个项目 ...