upc组队赛14 Bus stop【签到水】
Bus Stop
题目描述
In a rural village in Thailand, there is a long, straight, road with houses scattered along it.
(We can picture the road as a long line segment, with an eastern endpoint and a western endpoint.) The Thai government is planning to set up bus stops on this road in such a way that every house is within ten kilometers of one of the stops. What is the minimum number of stops the government need to set up to satisfy the requirement?
输入
The first line contains a single integer m representing the number of the test cases. Eachtest case consists of the following two lines:
The first line contains a single integer n representing the number of houses on the road, where 0 ≤ n ≤ 2,000,000.
The second line contains n integers h1 h2 … hn representing the locations of the houses in kilometers as measured from the start of the road, where 0 ≤ hi ≤ 90,000,000. That is, the first house is h1 kilometers away from the start of the road, the second house is h2 kilometers
away from the start of the road, and so on. You may assume that hi ’s are sorted in ascending order, e.g., h1 ≤ h2 ≤ h3 ≤ … ≤ hn .
输出
For each test case, print out in a single line the minimum number of bus stops that satisfy the requirement.
样例输入
2
5
1 2 3 200 210
4
10 30 80 200
样例输出
2
3
题意
建立公交站 每个站的范围是10 给你一些位置问需要多少个公交站
题解
水题 从头遍历 记录上一个站的位置 如果不在上一个站范围内 就重建一个
代码
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define scac(x) scanf("%c",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pri3(x,y,z) printf("%d %d %d\n",x,y,z)
#define prl(x) printf("%lld\n",x)
#define prl2(x,y) printf("%lld %lld\n",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define ll long long
#define LL long long
#define pb push_back
#define mp make_pair
#define P pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 5005
const int maxn = 2000005;
int t,n;
int a[maxn];
int main()
{
sca(t);
while(t--)
{
sca(n);
rep(i,0,n)
sca(a[i]);
int mx = -100;
int ans = 0;
rep(i,0,n)
{
if(mx + 10 < a[i])
{
mx = a[i] + 10;
ans++;
}
}
pri(ans);
}
}
upc组队赛14 Bus stop【签到水】的更多相关文章
- upc组队赛16 Melody【签到水】
Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...
- upc组队赛14 As rich as Crassus【扩展中国剩余定理】
As rich as Crassus 题目链接 题目描述 Crassus, the richest man in the world, invested some of his money with ...
- upc组队赛14 Floating-Point Hazard【求导】
Floating-Point Hazard 题目描述 Given the value of low, high you will have to find the value of the follo ...
- upc组队赛14 Communication【并查集+floyd /Tarjan】
Communication 题目描述 The Ministry of Communication has an extremely wonderful message system, designed ...
- upc组队赛14 Evolution Game【dp】
Evolution Game 题目描述 In the fantasy world of ICPC there are magical beasts. As they grow, these beast ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- upc组队赛3 Iranian ChamPions Cup
Iranian ChamPions Cup 题目描述 The Iranian ChamPions Cup (ICPC), the most prestigious football league in ...
- codeforces 711A A. Bus to Udayland(水题)
题目链接: A. Bus to Udayland 题意: 找一对空位坐下来,水; 思路: AC代码: #include <iostream> #include <cstdio> ...
- upc组队赛1 不存在的泳池【GCD】
不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...
随机推荐
- Python入门习题10.河内塔(汉诺塔)问题
例10 共n个圆盘,a,b,c三根柱子 #汉诺塔问题.py def Hanoi(n): #定义n阶汉诺塔问题移动次数函数 if n == 1: return 1 else: return 2*Hano ...
- python-MySQL数据库--- 基础篇
MySQL数据库基础 数据库系统(database system) 1.数据库系统(database system) 数据库系统是计算机系统中一种专门管理数组资源的系统,数据库存储的是 ...
- sqlserver创建索引语句
CREATE INDEX PersonIndex ON 表名 (字段名) DROP INDEX PersonIndex ON 表名
- elementUI 导航栏点击之后改变背景色,背景色悬停
一开始设置的是: .menuLeft .el-menu-item:hover{ background: #6db6ff !important; } .menuLeft .el-submenu__tit ...
- SR-IOV
SR-IOV 来源 http://blog.csdn.net/liushen0916/article/details/52423507 摘要: 介绍SR-IOV 的概念.使用场景.VMware 和 K ...
- 【JAVA】java中的length和length()
参考链接: 你注意到Java中的length和length()了吗?外加一个size() java中的求长度length有时有小括号,有时没有小括号,到底什么时候该加小括号呢? 总结: Java中St ...
- elasticsearch 深入 —— Scroll滚动查询
Scroll search 请求返回一个单一的结果"页",而 scroll API 可以被用来检索大量的结果(甚至所有的结果),就像在传统数据库中使用的游标 cursor. 滚动并 ...
- RabbitMQ基于Stomp实现与MQTT客户端通信
请参照RabbitMQ应用和SpringBoot集成RabbitMQ并实现消息确认机制 详情参照官方文档https://www.rabbitmq.com/stomp.html.https://gith ...
- 关于javascript中的构造函数和普通函数探索 [转]
这是第一篇关于javascript模块的文章,在javascript入门的目录下,主要是记录一些对网上精彩的js研读碰到的疑惑,并做一些实验和探索 关于js中的对象和方法的定义博主感到非常的迷惑.针对 ...
- 一网打尽 @ExceptionHandler、HandlerExceptionResolver、@controlleradvice 三兄弟!
把 @ExceptionHandler.HandlerExceptionResolver.@controlleradvice 三兄弟放在一起来写更有比较性.这三个东西都是用来处理异常的,但是它们使用的 ...