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 ...
随机推荐
- mybatis(二)全局配置mybatis-config.xml
转载:https://www.cnblogs.com/wuzhenzhao/p/11092526.html 大部分时候,我们都是在Spring 里面去集成MyBatis.因为Spring 对MyBat ...
- 全方位构造免杀 webshell 小结[一]
转载自https://klionsec.github.io/2017/10/11/bypasswaf-for-webshell/ 全方位构造免杀 webshell 小结[一] 前言: 本 ...
- Apple WWDC All In One
Apple WWDC All In One https://developer.apple.com/wwdc20/ https://developer.apple.com/videos/wwdc202 ...
- Android 如何设置 WebView 的屏幕占比
Android 如何设置 WebView 的屏幕占比 由于 Android 适用于具有各种屏幕尺寸和像素密度的设备,因此您在设计网页时应将这些因素纳入考虑范围,以便您的网页始终以合适的尺寸显示. We ...
- 从长度为 M 的无序数组中,找出N个最小的数
从长度为 M 的无序数组中,找出 N个最小的数 在一组长度为 n 的无序的数组中,取最小的 m个数(m < n), 要求时间复杂度 O(m * n) 网易有道面试题 const minTopK ...
- yarn & uninstall global & yarn global remove
yarn uninstall global yarn global remove https://yarnpkg.com/lang/en/docs/cli/remove/ https://yarnpk ...
- Flutter 将TextField平滑过渡到Text
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends State ...
- Masterboxan INC发布《2019年可持续发展报告》
近日,Masterboxan INC万事达资产管理有限公司(公司编号:20151264097)发布<2019年可持续发展报告>,全面回顾了在过去一年Masterboxan INC开展的可持 ...
- Captain Technology INC浅谈新能源汽车的未来
近日全世界上最大的资管公司贝莱德向位于的英国电动汽车初创公司Arrival投资1.18亿美元,且该公司已有投资者亚马逊和美国第二大汽车制造商福特汽车参投.中国最知名的电动车公司蔚来股价单日大涨22%, ...
- Zookeeper从入门到删库跑路
导语 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等.Zookeeper是hadoop的一个子项 ...