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 ...
随机推荐
- python argparse (更新中)
action='store_true' 例如 parser.add_argument("--generate_text_embedding", action='store_true ...
- 近期做的一些DP
UVa 1625 color length https://blog.csdn.net/Dylan_Frank/article/details/52261424 https://www.cnblogs ...
- RT-Thread学习笔记2-互斥量与信号量
目录 1. 临界区保护 1.1 方法一:关闭系统调度保护临界区 1.2 方法二:互斥特性保护临界区 2. 信号量 2.1 信号量的定义 2.2 信号量的操作 3. 生产者.消费者问题 4. 互斥量 4 ...
- php foundation knowledge!
php foundation knowledge! 1 <?php 2 $p = "PII"; 3 define("XPI",3.1415926); 4 ...
- CSS hover box
CSS hover box transition 踩坑指南, display: none; 作为初始状态,不会产生动画效果,必须设置 height: 0; 或 width: 0; 来实现隐藏! tra ...
- shit api & shit antd
shit api & shit antd 代码演示 ??? https://ant.design/components/skeleton-cn/ https://github.com/ant- ...
- npx & yarn & npm
npx & yarn & npm React Redux App https://reactjs.org/ https://github.com/facebook/create-rea ...
- perl 打印目录结构
更多 #!/usr/bin/perl # 递归打印目录结构 use v5.26; use strict; use utf8; use autodie; use warnings; use Encode ...
- NGK DeFi项目即将上线,打造去中心化闭环金融生态!
据最新官方消息称:NGK已于近日宣布将进军DeFi领域,NGK此次的DeFi的项目将会是一个去中心的交易平台,其最大的功能是进行数字货币的交换.在用户选择了需要支付的数字货币和想购买的数字货币后,系统 ...
- 怎么创建CSV文件和怎么打开CSV文件
CSV(Comma Separated Values逗号分隔值). .csv是一种文件格式(如.txt..doc等),也可理解.csv文件就是一种特殊格式的纯文本文件.即是一组字符序列,字符之间已英文 ...