zoukankan      html  css  js  c++  java
  • 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
    ",x)
    #define pri2(x,y) printf("%d %d
    ",x,y)
    #define pri3(x,y,z) printf("%d %d %d
    ",x,y,z)
    #define prl(x) printf("%lld
    ",x)
    #define prl2(x,y) printf("%lld %lld
    ",x,y)
    #define prl3(x,y,z) printf("%lld %lld %lld
    ",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);
      }
    }
    
  • 相关阅读:
    web 开发之酷炫--- 酷炫展示
    攻城狮的体检
    科技发烧友之智能路由
    科技发烧友之3d吉米投影
    科技发烧友之单反佳能700d中高端
    上海
    视频会议
    机器学习之信息
    filter
    centos 20T硬盘(超过16T)分区
  • 原文地址:https://www.cnblogs.com/llke/p/10806182.html
Copyright © 2011-2022 走看看