2019 GDUT Rating Contest II : Problem B. Hoofball
题面:
B. Hoofball
题目描述:
题目分析:






- 1 #include <cstdio>
- 2 #include <cstring>
- 3 #include <iostream>
- 4 #include <cmath>
- 5 #include <set>
- 6 #include <algorithm>
- 7 using namespace std;
- 8 int x[105];
- 9 char s[105];
- 10 int mmap[105];
- 11
- 12 int main(){
- 13 int n;
- 14 cin >> n;
- 15 for(int i = 0; i < n; i++) cin >> x[i];
- 16
- 17 sort(x, x+n);
- 18 for(int i = 0; i < n; i++){
- 19 if(i == 0) s[i] = '>'; //开始方向为右
- 20 else if(i == n-1) s[i] = '<'; //结尾方向为左
- 21 else{
- 22 int a, b;
- 23 a = abs(x[i]-x[i-1]);
- 24 b = abs(x[i]-x[i+1]);
- 25 if(a > b){
- 26 s[i] = '>';
- 27 }
- 28 else if(a <= b){
- 29 s[i] = '<';
- 30 }
- 31 }
- 32 }
- 33
- 34 s[n] = '>'; //方便判断用,建议先看下面再上来理解这个
- 35 int cnt = 0; //球的数量
- 36 for(int i = 0; i < n; ){
- 37 int flag = 0; //箭头向右的数量
- 38 while(s[i] == '>' && i < n) {i++; flag++;}
- 39 //循环说明s[i] == '<'或者遍历完了
- 40 if(s[i+1] == '>') {cnt++; i++;} //如果下一个点是另一个图,进行计数,然后到下一个点(这个包含第一种和第二种情况)
- 41 else{
- 42 while(s[i] == '<' && i < n) i++;
- 43 if(flag > 1) cnt += 2; //两个以上向右的箭头(此时这个图向左的箭头超过了两个才会到这一步),就是第四种情况
- 44 else cnt++; //第三种情况
- 45 }
- 46 }
- 47
- 48 cout << cnt << endl;
- 49 return 0;
- 50 }
2019 GDUT Rating Contest II : Problem B. Hoofball的更多相关文章
- 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 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 II : A. Taming the Herd
题面: A. Taming the Herd Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 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 ...
随机推荐
- Http和Https之为什么Https更安全
[除夕了,加油干.希望自己新的一年万事顺意,祝大家身体健康,心想事成!] 我们都知道 HTTPS 安全,可是为什么安全呢? 看小电影还是浏览正常网站,一定要检查是不是 HTTPS 的,因为Https相 ...
- matplotlib 图标显示中文
matplotlib 显示中文 Method_1: # 添上: plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcPara ...
- CSS :nth-of-type() bug
CSS :nth-of-type() bug .tools-hover-box-list-item { pointer-events: auto; box-sizing: border-box; di ...
- how to create a style element in js (many ways)
how to create a style element in js (many ways) create style in js Constructed StyleSheets CSSStyleS ...
- ES6 & tagged-template-literals & template strings
ES6 & tagged-template-literals & template strings tagged template https://developer.mozilla. ...
- Dart 中断Future
更多 中断future 方法1) import 'package:async/async.dart'; void main() { var get = CancelableOperation.from ...
- Linux 内核和 Windows 内核有什么区别?
Windows 和 Linux 可以说是我们比较常见的两款操作系统的. Windows 基本占领了电脑时代的市场,商业上取得了很大成就,但是它并不开源,所以要想接触源码得加入 Windows 的开发团 ...
- Redis 对过期数据的处理
Redis 对过期数据的处理 在 redis 中,对于已经过期的数据,Redis 采用两种策略来处理这些数据,分别是惰性删除和定期删除 惰性删除 惰性删除不会去主动删除数据,而是在访问数据的时候,再检 ...
- Mybatis-05 注解开发
Mybatis-05 注解开发 注解开发 注解的核心是反射机制 面向接口编程的根本原因:解耦,可拓展,提高复用,分层开发中.上层不用管具体的实现,大家都遵守共同的标准,使得开发变得容易,规范性好. 1 ...
- re模块之简单计算器的实现
本节大纲: 表达式的输入及检查.格式化 怎么样进行匹配最里面的括号以及操作数的匹配 如何实现表达式的四则运算 完整代码展示 在我们学习re模块之后,通常的练习就是利用所学相关知识来写一个计算器 那么, ...