水题:HDU 5112 A Curious Matt
Description
One day, Matt's best friend Ted is wandering on the non-negative half of the number line. Matt finds it interesting to know the maximal speed Ted may reach. In order to do so, Matt takes records of Ted’s position. Now Matt has a great deal of records. Please help him to find out the maximal speed Ted may reach, assuming Ted moves with a constant speed between two consecutive records.
Input
For each test case, the first line contains an integer N (2 ≤ N ≤ 10000),indicating the number of records.
Each of the following N lines contains two integers t i and x i (0 ≤ t i, x i ≤ 10 6), indicating the time when this record is taken and Ted’s corresponding position. Note that records may be unsorted by time. It’s guaranteed that all t i would be distinct.
Output
Sample Input
2
3
2 2
1 1
3 4
3
0 3
1 5
2 0
Sample Output
Case #1: 2.00
Case #2: 5.00
Hint
In the first sample, Ted moves from 2 to 4 in 1 time unit. The speed 2/1 is maximal. In the second sample, Ted moves from 5 to 0 in 1 time unit. The speed 5/1 is maximal.
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N=;
int tim[N],pos[N],p[N];
bool cmp(int x,int y){
return tim[x]<tim[y];
}
int main(){
int T,n,cas=;
double ans;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&tim[i],&pos[i]);
p[i]=i;
}
sort(p+,p+n+,cmp);
ans=0.0;
for(int i=;i<=n;i++)
ans=max(ans,fabs(pos[p[i]]-pos[p[i-]])/fabs(tim[p[i]]-tim[p[i-]]));
printf("Case #%d: %.2f\n",++cas,ans);
}
return ;
}
水题:HDU 5112 A Curious Matt的更多相关文章
- hdu 5112 A Curious Matt
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5112 A Curious Matt Description There is a curious ma ...
- HDU 5112 A Curious Matt 水题
A Curious Matt Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)
A Curious Matt Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) ...
- hdoj 5112 A Curious Matt
A Curious Matt Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) ...
- HDU 5120 A Curious Matt(2014北京赛区现场赛A题 简单模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112 解题报告:扫一遍 #include<cstdio> #include<cstr ...
- 水题~~~~HDU 4788
Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gi ...
- 又是一道水题 hdu背包
Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
随机推荐
- 大数据应用:五大地区喜新厌旧游戏APP类别之比较与分析
今天,我们来分享点不一样的资讯.....游戏APP之喜新厌旧排行榜!! 前阵子笔者开发了一套系统可以用来收集亚洲五大地区上架APP的每日排名信息,希望观察出五大地区在APP上的喜好和使用程度之间的相异 ...
- 【转】Java中equals和==的区别
[转]Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boole ...
- (转)spring ioc原理(看完后大家可以自己写一个spring)
最近,买了本Spring入门书:spring In Action .大致浏览了下感觉还不错.就是入门了点.Manning的书还是不错的,我虽然不像哪些只看Manning书的人那样专注于Manning, ...
- Java-Android 之应用停止错误
在Android在手机上运行的时候: 经常会出现应用程序停止: 一: 因为触发的方法里面没有传值View 对象,方法报错
- PHP获得header头进行分析
学web的人都知道,要深刻的理解就一定要对HTTP协议有深刻的理解,这样你才能理解整个运行的流程,有些功能你才能理解应该 如何去实现,比如:仿盗链啊,定义IP后切换页面语种的版本啊,等等, 这里就来对 ...
- UITableView中容易忽略的知识点
1.取消余下的分割线 tableView.tableFooterView = UIView() 2.分割线顶格 override func viewDidLayoutSubviews() { self ...
- Struts2输入校验
1.编写校验规则文件 (<ActionName>-validation.xml),文件放在Action类文件相同的路径下校验失败返回input的result. <vali ...
- MOOC即Massive Open Online Course的缩写
A man can succeed at almost anything for which he was unlimited enthusiasm. 只要有无限的热情,一个人几乎可以在任何事情上取得 ...
- 需求分析Point
1.码段的查询结果的汇总值计算有问题.被删除的是否还算是被使用范围内呢?现在是即使废弃了也算使用的.这就有范围和重叠的问题,需要识别这种集合关系的数据好概念,并搞清楚他们的关系和概念.
- LightOJ_1248 Dice (III)
题目链接 题意: 给一个质地均匀的n的骰子, 求投掷出所有点数至少一次的期望次数. 思路: 这就是一个经典的邮票收集问题(Coupon Collector Problem). 投掷出第一个未出现的点数 ...