题目链接: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. Github Docs All In One

    Github Docs All In One docs https://docs.github.com/en https://github.com/github/docs GitHub REST AP ...

  2. Awesome GitHub Topics

    Awesome GitHub Topics freeCodeCamp https://github.com/topics/javascript?o=desc&s=stars https://g ...

  3. C++ 0LL

    C++ 0LL C plus plus L / l means long LL === long long int countDigitOne(int n) { int countr = 0; for ...

  4. js & touch & pull down & load more

    js & touch & pull down & load more https://www.jianshu.com/p/93597d6bd77d index-list htt ...

  5. 移动端 750px UI 设计稿

    750px UI 设计稿 App 小程序 H5 rem & vh/vw 在移动端页面开发中,UI 一般会用750px(iphone 6)来出设计稿; 然后要求能够做到页面是自适应屏幕的,这种情 ...

  6. Flutter 设置input边框

    example 1 import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp ext ...

  7. webpack + ts 配置路径别名无死角方法总结

    webpack + ts 配置路径别名总结 自我体验加总结:在配置脚手架时,定制别名很有必要,可以使得代码更优雅,可读性更强.但在使用ts的时候,即便项目能够运行,vscode 确时长会提示 can' ...

  8. 【从零开始撸一个App】Fragment和导航中的使用

    Fragment简介 Fragment自从Android 3.0引入开始,它所承担的角色就是显而易见的.它之于Activity就如html片段之于页面,好处无需赘述. Fragment的生命周期和Ac ...

  9. Unity 定点投射固定高度抛物线

    假设同一平面中有AB两点,A点向B点水平射击,很容易想象子弹会沿由A指向B的向量方向前进,经过时间t后到达B点,若此时A点不再水平射击,改为以抛物线的方式向B点投射,同样需要在时间t后击中B点,那么如 ...

  10. Vue学习笔记-jsonl转换显示工具JsonView安装及使用

    一  使用环境: windows 7 64位操作系统 二  jsonl转换显示工具JsonView安装及使用 1.下载: https://github.com/gildas-lormeau/JSONV ...