Problem Description

Bessie is traveling on a road teeming with interesting landmarks. The road is labeled just like a number line, and Bessie starts at the "origin" (x = 0). A total of N (1 ≤ N ≤ 50,000) landmarks are located at points x1, x2, ..., xN (-100,000 ≤ xi ≤ 100,000). Bessie wants to visit as many landmarks as possible before sundown, which occurs in T (1 ≤ T ≤ 1,000,000,000) minutes. She travels 1 distance unit in 1 minute.

Bessie will visit the landmarks in a particular order. Since the landmarks closer to the origin are more important to Farmer John, she always heads for the unvisited landmark closest to the origin. No two landmarks will be the same distance away from the origin.
Help Bessie determine the maximum number of landmarks she can visit before the day ends.

Input

Line 1: Two space-separated integers: T and N

Lines 2..N+1: Line i+1 contains a single integer that is the location of the ith landmark: xi

Output

Line 1: The maximum number of landmarks Bessie can visit.

Sample Input

25 5

10
-3
8
-7
1

Sample Output

4

题意:一条数轴上,给n个点,从原点出发,优先达到距离原点最近的点,求t秒内到达的点的最大数量。

思路:点的坐标有正有负,升序排序时按绝对值大小排序,然后计算t秒内到达的最大数量即可。

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 100001
#define MOD 2520
#define E 1e-12
using namespace std;
int a[N];
bool cmp(int x,int y)
{return abs(x)<abs(y);
}
int main()
{int t,n;scanf("%d%d",&t,&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+1+n,cmp);int cnt=0;int use=0;//已用时间int k=1;if(a[1]==0){cnt=1;k++;}for(int i=k;i<=n;i++){int time=abs(a[i]-a[i-1]);if(time<=t-use)//若时间足够,则前往下一点{cnt++;use+=time;//累计已用时间}elsebreak;}printf("%d\n",cnt);return 0;
}

Exploration(POJ-3618)相关推荐

  1. Bailian2734 十进制到八进制【入门】(POJ NOI0113-45)

    问题链接:POJ NOI0113-45十进制到八进制 2734:十进制到八进制 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个十进制正整数转化成八进制. 输入 一行,仅含一个十进 ...

  2. Bailian2676 整数的个数【入门】(POJ NOI0105-11)

    问题链接:POJ NOI0105-11 整数的个数 2676:整数的个数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定k(1 < k < 100)个正整数,其中每个数 ...

  3. Bailian4029 数字反转【进制】(POJ NOI0105-29)

    问题链接:POJ NOI0105-29 数字反转 4029:数字反转 总时间限制: 1000ms 内存限制: 65535kB 描述 给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数 ...

  4. Bailian2735 八进制到十进制【入门】(POJ NOI0113-46)

    问题链接:POJ NOI0113-46 八进制到十进制 2735:八进制到十进制 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个八进制正整数转化成十进制. 输入 一行,仅含一个八 ...

  5. Silver Cow Party (POJ - 3268 )

    Silver Cow Party (POJ - 3268 ) 这道题是我做的最短路专题里的一道题,但我还没做这个,结果比赛就出了,真是.......... 题目: One cow from each ...

  6. 吴昊品游戏核心算法 Round 7 —— 熄灯游戏AI(有人性的Brute Force)(POJ 2811)

    暴力分为两种,一种属于毫无人性的暴力,一种属于有人性 的暴力.前面一种就不说了,对于后面一种情况,我们可以只对其中的部分问题进行枚举,而通过这些子问题而推导到整个的问题中.我称之为有人性的Brute ...

  7. 【二分】Best Cow Fences(poj 2018)

    Best Cow Fences poj 2018 题目大意: 给出一个正整数数列,要你求平均数最大,长度不小于M的字串,结果乘1000取整 输入样例 10 6 6 4 2 10 3 8 5 9 4 1 ...

  8. 昂贵的聘礼(poj 1062)

    Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...

  9. 主席树学习小结(POJ 2104)

    在高中的时候就听到过主席树了,感觉非常高端,在寒假的时候 winter homework中有一题是查找区间第K大的树,当时就开始百度这种网上的博客,发现主席树看不懂,因为那个root[i],还有tx[ ...

  10. A - TOYS(POJ - 2318) 计算几何的一道基础题

    Calculate the number of toys that land in each bin of a partitioned toy box. 计算每一个玩具箱里面玩具的数量 Mom and ...

最新文章

  1. 软件工程项目组Z.XML会议记录 2013/09/18
  2. Android开发之android_apk 在线安装(源代码分享)
  3. C#抽象类与接口的区别【转】
  4. 研发手Q推广遇到的一系列问题
  5. python两个元组相加_《第5章 Python 列表与元组》5.1.3 序列相加(Adding)!
  6. NSURLProtocol 拦截 NSURLSession 请求时body丢失问题解决方案探讨
  7. python 内置_python 内置
  8. PGM:贝叶斯网的参数估计
  9. C++ queue队列如何遍历
  10. 信工所复试(专业面)
  11. 背包问题大全(动态规划)
  12. 聊聊数字姓氏:这个姓氏真占便宜,被称为最容易夺冠的姓氏!
  13. 世界杯数据清单:真球迷看球必备,伪球迷速成指南(附数据amp;论文)
  14. 计算机无法验证签名,电脑提示“无法验证此文件的数字签名”的修复方法
  15. 冰蝎shell_冰蝎动态二进制加密WebShell特征分析
  16. 气传导蓝牙耳机哪个牌子好?口碑好的气传导耳机分享
  17. 电线线缆铜芯和铝芯有什么区别?哪个更好呢?
  18. redis查看某一个key的大小_redis查询key的内存大小
  19. 现在完成时的被动语态和动词的过去分词做形容词
  20. java module和model_Java9-Modularity 初探

热门文章

  1. 终于有人把AI、BI、大数据、数据科学讲明白了
  2. 人人都可以创造自己的AI:深度学习的6大应用及3大成熟领域
  3. 清华大学计算机科学与技术在哪个楼,清华大学计算机科学与技术系宿舍
  4. 多个html网页共享变量,多个jsp页面共享一个js对象的超级方法
  5. 金蝶软件怎么过账_代理记账用什么财务软件?
  6. 我的新书终于写完了。
  7. 一文彻底搞懂Cookie、Session、Token到底是什么
  8. 面试官,求求你不要问我这么简单但又刁难的算法题了
  9. 再见,Eclipse
  10. 万字长文 | 淘宝 10年架构演进