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 ...
随机推荐
- Win10 Nodejs搭建http-server注意点
下载安装,并用命令行查看版本:如果提示输入命令找不到等,可能是没有安装成功,或者是环境变量引起的: 如果在提示安装不成功可能是win10权限问题,最好使用管理员模式运行cmd,再用cmd命令打开安装文 ...
- Gym 101128J Saint John Festival(凸包 + 二分判点和凸包关系)题解
题意:给你一堆黑点一堆红点,问你有最多几个黑点能找到三个红点,使这个黑点在三角形内? 思路:显然红点组成的凸包内的所有黑点都能做到.但是判断黑点和凸包的关系朴素方法使O(n^2),显然超时.那么我现在 ...
- macOS 没有鼠标 怎么使用 快捷键
macOS 没有鼠标 怎么使用 快捷键 mini 链接蓝牙鼠标 菜单选择 光标聚焦 上下选择 确认,选中 用键盘浏览菜单 若要使用这些快捷键,请先按下 Control-F2 或 Fn-Control- ...
- TypeScript Developer Roadmap
TypeScript Developer Roadmap https://github.com/xgqfrms/TypeScript-Developer-Roadmap https://typescr ...
- Promise nested then execute order All In One
Promise nested then execute order All In One Promise nested then nested Promise not return new Promi ...
- js & bitwise-operators
js & bitwise-operators 不用加减乘除运算符, 求整数的7倍 "use strict"; /** * * @author xgqfrms * @lice ...
- Android Studio & Flutter Plugins & Dart plugins
Android Studio & Flutter Plugins & Dart plugins https://flutter.dev/docs/get-started/editor? ...
- NGK英国路演圆满结束,未来科技布局看好NGK公链技术
近日,NGK全球路演英国站在首都伦敦圆满结束.区块链业内专家.各投行精英.各市场节点代表.八大产业代表参加了此次路演.同时,英国经济学人.每日邮报.金融时报等近百家财经媒体对此路演进行了大力报道.并且 ...
- 200万枚SPC空投来袭,这样的薅羊毛活动你确定不参加吗?
在过去的2020年,币圈真的是很火爆,很多人在参与数字货币交易或DeFi挖矿中赚到了大钱.但是转眼到了2021年,DeFi进入了下半场,区块链市场也进入了新的阶段,那么区块链的下一个爆点是什么呢?很多 ...
- 【SVM】kaggle之澳大利亚天气预测
项目目标 由于大气运动极为复杂,影响天气的因素较多,而人们认识大气本身运动的能力极为有限,因此天气预报水平较低,预报员在预报实践中,每次预报的过程都极为复杂,需要综合分析,并预报各气象要素,比如温度. ...