水题: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 ...
随机推荐
- Bootstrap-全局css样式之按钮
这里所说的按钮只是Bootstrap设计的能使标签或元素呈现按钮样式的属性,所以为 <a>.<button> 或 <input> 元素添加按钮类(button cl ...
- Linux上安装KDE, Gnome和VNC
安装所需环境:需要至少256m的可用内存(128也可以不过有点卡)CentOS或类似OS(Debian的话改成apt-get应该也可以) 1,安装KDE 1 yum install kdepim 或安 ...
- (二)Struts2 核心知识
所有的学习我们必须先搭建好Struts2的环境(1.导入对应的jar包,2.web.xml,3.struts.xml) 第一节:Struts2 get/set 自动获取/设置数据 action代码: ...
- 解决UICollectionView ReloadData闪一下(隐式动画)
方式一: [UIView setAnimationsEnabled:NO]; [collectionView performBatchUpdates:^{ [collectionView reload ...
- 5 DML语言
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- 用原生js实现一个页面乘法口诀表
今天我自己用js实现了一个页面乘法口诀表(如图)来共享给大家,做的不是很好,如果大家有新的想法可以跟我交流哦. 代码如下: <!doctype html><html lang=&qu ...
- 一天学完UFLDL
学习UFLDL笔记 第一节 神经网络 神经元长这样 大写W看着有点不习惯.. 激活函数, 就是上面式子中的f. 可以选 sigmoid函数(或者叫 logistic回归,对数几率函数),反正就是这样一 ...
- ajax只是一个称呼
记得刚入行的时候,看到ajax,即异步的javascript和xml这样一个概念,一点感觉都没有.参加工作前的第一轮面试,被问到有没有自己实现过ajax,我觉得自己实现肯定很复杂吧. 从名字理解 从名 ...
- node 后台ajax文件(同时支持http、https)
var http = require("http"), Url = require("url"), querystring = require('queryst ...
- 开启/关闭ubuntu防火墙
LInux原始的防火墙工具iptables由于过于繁琐,所以ubuntu系统默认提供了一个基于iptable之上的防火墙工具ufw.而UFW支持图形界面操作,只需在命令行运行ufw命令即能看到一系列的 ...