题目链接:https://vjudge.net/problem/Gym-102569B

题意:数轴上有N个点,从0出发最多走t步问最多经过几个点。

思路:分开存负数点和整数点,然后枚举每个端点,某个点的距离*2+往反方向走距离<t。利用upper_bound()查找位置即可。(例如枚举左端点时,找出往右走最多的点)

 1 #include <bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4 vector <ll> f,z;
5 int main()
6 {
7 ll n,t;
8 scanf("%lld%lld",&n,&t);
9 for(int i=0;i<n;i++)
10 {
11 ll x;
12 scanf("%lld",&x);
13 if(x>0) z.push_back(x);
14 else f.push_back(-x);
15 }
16 sort(f.begin(),f.end());
17 sort(z.begin(),z.end());
18 ll ans=0;
19 for(int i=0;i<f.size();i++)
20 {
21 if(f[i]>t) break;
22 ll maxd=t-2*f[i];
23 ll res=0;
24 if(maxd>0) res=upper_bound(z.begin(),z.end(),maxd)-z.begin();
25 ans=max(ans,res+i+1);
26 }
27 for(int i=0;i<z.size();i++)
28 {
29 if(z[i]>t) break;
30 ll maxd=t-2*z[i];
31 ll res=0;
32 if(maxd>0) res=upper_bound(f.begin(),f.end(),maxd)-f.begin();
33 ans=max(ans,res+i+1);
34 }
35 printf("%lld\n",ans);
36 return 0;
37 }

Bonuses on a Line Gym - 102569B的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. HDU 3247 Resource Archiver(AC自动机 + 状压DP + bfs预处理)题解

    题意:目标串n( <= 10)个,病毒串m( < 1000)个,问包含所有目标串无病毒串的最小长度 思路:貌似是个简单的状压DP + AC自动机,但是发现dp[1 << n][ ...

  2. Mapbox 地图实验室

    Mapbox 地图实验室 Learn with Mapbox https://www.mapbox.com/community/education/ https://labs.mapbox.com/e ...

  3. windows 10 remote desktop

    windows 10 remote desktop https://support.microsoft.com/en-us/help/4028379/windows-10-how-to-use-rem ...

  4. Bastion Host (BH)

    Bastion Host (BH) 堡垒机 堡垒主机是专门设计和构造成承受攻击网络上的专用计算机. 该计算机通常承载单个应用程序,例如代理服务器,并且所有其他服务都将被删除或限制以减少对计算机的威胁. ...

  5. apollo-server 返回模拟数据

    模式模拟GraphQL数据 const { ApolloServer, gql } = require('apollo-server'); const typeDefs = gql` type Que ...

  6. Flutter: SliverAppBar 应用程序栏与滚动视图集成,以便它可以根据滚动偏移量在高度上变化

    API class _MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin { @override W ...

  7. Dyno-queues 分布式延迟队列 之 生产消费

    Dyno-queues 分布式延迟队列 之 生产消费 目录 Dyno-queues 分布式延迟队列 之 生产消费 0x00 摘要 0x01 前情回顾 1.1 设计目标 1.2 选型思路 0x02 产生 ...

  8. nginx判断状态脚本

    A是nginx行数 为0则启动nginx 启动失败则杀死keepalived进程

  9. 微信小程序:小程序中使用Less

    配置: 首选项 -> 设置 -> 用户 -> 扩展 (找到EasyLess插件,编辑setting.json文件进行配置) 点击vscode左下角的à设置à点击右上角的à添加以上代码 ...

  10. SpringBoot 配置文件以及依赖 加上跨域配置文件

    配置目录: application.properties的配置 #设置服务端口号 server.port = 8090 #配置数据源 spring.datasource.driver-class-na ...