Exploration
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4904 Accepted: 2370

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

Source

USACO 2007 November Bronze

问题链接:POJ3618 Exploration
问题简述:输入的第1行是T和N,分别表示时间和点的数量,然后是数轴上的N个点的到原点的时间。从原点出发,按距离原点最近的顺序,访问这些点。问时间t内可以达到的点的最大数量?
问题分析:为了方便顺序计算点到点直接需要的时间,进行绝对值排序,这样顺序计算就可以了。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* POJ3618 Exploration */#include <iostream>
#include <algorithm>
#include <cstdio>using namespace std;const int N = 50000;
int a[N];bool cmp(int a, int b)
{return abs(a) < abs(b);
}int main()
{int t, n;scanf("%d%d", &t, &n);for(int i = 0; i < n; i++) scanf("%d", &a[i]);sort(a, a + n, cmp);int t2 = abs(a[0]), cnt = 1;for(int i = 1; i < n; i++)if((t2 += abs(a[i] - a[i - 1])) <= t) cnt++;else break;printf("%d\n", cnt);return 0;
}

POJ3618 Exploration【水题+排序】相关推荐

  1. 【HDU - 1031 】Design T-Shirt(水题 排序)

    题干: Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA found th ...

  2. poj 2291/3637 水题排序

    poj 2291题意:给你几根绳子,每根最大承重能力都不同,从中选出几根,问最大承重力量是多少?称重是选出绳子的最小值*根数(比如有1,10,15承重的3跟绳子,如果用一根的话,选15的,能承重15, ...

  3. poj 2388 排序的水题

    纯纯的水题. #include <iostream> #include <fstream> #include <cstdlib>using namespace st ...

  4. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  5. 水题 ZOJ 3875 Lunch Time

    题目传送门 1 /* 2 水题:找排序找中间的价格,若有两个,选价格大的: 3 写的是有点搓:) 4 */ 5 #include <cstdio> 6 #include <iostr ...

  6. HUST - 1016 幼儿园小朋友们的难题(水题)

    幼儿园的小朋友们一直在研究一个问题-- 如何在一个长长的句子中找到最大的那个非负整数(不存在负数).你很不幸的被他们拖住了,又很不幸的被他们叫去执行这个任务,你非常得不爽! 因为你觉得这么简单的问题简 ...

  7. 【CodeForces - 1201C】Maximum Median(思维,水题)

    题干: You are given an array aa of nn integers, where nn is odd. You can make the following operation ...

  8. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

  9. 1503171912-ny-一道水题

    一道水题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 今天LZQ在玩一种小游戏,可是这游戏数有一点点的大,他一个人玩的累.想多拉一些人进来帮帮他.你能写一个程序帮 ...

最新文章

  1. 一文详解随机一致性采样算法:RANSAC
  2. 收敛速度更快更稳定的Wasserstein GAN(WGAN)
  3. linux ssh 下实现免密码登录
  4. php复合索引,关于复合索引和单独索引的一个问题
  5. 迪米特法则(Law of Demeter) 简介
  6. C# 中特性(Attribute)的使用简介
  7. 认知:什么是真正的产品思维?
  8. 复练-关于面试的科技树-能力三核的彩蛋
  9. 嵌入式Linux系统编程学习之十一Linux进程的创建与控制
  10. 设计素材模板丨极简风简历模板
  11. lisp读点坐标绘多义线_AutoCAD中多义线的坐标标注
  12. 开源许可协议了解这些就够了
  13. 计算机语言学和语料库语言学的区别,浅谈语料库语言学与外语教学
  14. Cocos2dx--Cocos2dx与Android平台的跨平台调用
  15. 怎么连接win10共享计算机,xp系统下怎么连接win10共享的打印机
  16. python和ruby性能比较_Ruby和Python的比较
  17. noi题库1.1~1.6答案
  18. 音视频聊天开发: 1 视频采集
  19. 三、Java NIO Buffer
  20. word流程图怎么使箭头对齐_word流程图箭头怎么画

热门文章

  1. GIS制图课程目录(持续整理)
  2. MFC 教程【10_内存分配方式和调试机制 】
  3. MFC 教程【9_MFC的状态】
  4. 【java学习之路】(java SE篇)014.Stream API
  5. insert执行成功 没有数据_Python—接口测试数据库封装实现原理
  6. Doris之Routine Load
  7. nginx tornado php,tornado+nginx+python 微信公众号接入配置
  8. c++函数不允许递归_递归优化的这三种方式你知道吗?
  9. CUDA——线程配置
  10. OpenCV总结:图像增强算法实现(直方图均衡化、拉普拉斯、Log、Gamma)