题目链接: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 3966 Aragorn's Story(树链剖分)题解

    题意:给一棵树,要求你对一个路径上的值进行加减,查询某个点的值 思路:重链剖分. 由于分了轻重儿子,我每次到重儿子的top只要O(1),经过的轻儿子最多logn条,那么我每次往上跳最多跳logn次. ...

  2. Graphviz - Graph Visualization Software 开源可视化绘图工具(visio 类)

    http://www.graphviz.org/Download_windows.php Welcome to Graphviz Available translations:  Romanian,  ...

  3. infinite scroll blogs

    infinite scroll blogs 无限滚动 blogs beacon api https://www.sitepoint.com/introduction-beacon-api/ Histo ...

  4. random array & shuffle 洗牌算法 / 随机算法

    random array & shuffle shuffle 洗牌算法 / 随机算法 https://en.wikipedia.org/wiki/Fisher–Yates_shuffle ES ...

  5. script async / defer

    script async / defer preload / prefetch https://abc.xgqfrms.xyz/ https://javascript.info/script-asyn ...

  6. BGV上线两天价格超过880美金,下一个YFI已到来!

    BGV自上线以来就备受币圈关注,众多投资者纷纷表示看好BGV.BGV也不负众望,在上线交易所第二天,价格就迎来了暴涨,最高价格为888.88美金,超越了当前以太坊的价值.而这也迎来了币圈众多投资者的一 ...

  7. postman功能介绍

  8. Java中的CPU占用高和内存占用高的问题排查

    下面通过模拟实例分析排查Java应用程序CPU和内存占用过高的过程.如果是Java面试,这2个问题在面试过程中出现的概率很高,所以我打算在这里好好总结一下. 1.Java CPU过高的问题排查 举个例 ...

  9. 权限管理整合springsecurity代码执行过程

    (1)输入用户名密码. (2)进入认证过滤器中,执行attemptAuthentication方法, 通过该方法获取输入的用户名和密码. (3)执行实现了UserDetailsService接口的类中 ...

  10. canal数据同步 客户端代码实现

    1.引入相关依赖 <dependencies> <dependency> <groupId>org.springframework.boot</groupId ...