hdu 5112 A Curious Matt
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5112
A Curious Matt
Description
There is a curious man called Matt.
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
The first line contains only one integer $T$, which indicates the number of test cases.
For each test case, the first line contains an integer $N\ (2 \leq N \leq 10000)$,indicating the number of records.
Each of the following $N$ lines contains two integers $t_i$ and $x_i$ $(0 \leq t_i, x_i \leq 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 ti would be distinct.
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1), and y is the maximal speed Ted may reach. The result should be rounded to two decimal places.
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
简单题,权当练习一下英文。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::max;
using std::cin;
using std::cout;
using std::endl;
using std::fabs;
using std::sort;
using std::pair;
using std::vector;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
struct Node {
int t, x;
bool operator<(const Node &b) const {
return t < b.t;
}
}rec[N];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t, n, k = ;
scanf("%d", &t);
while (t--) {
double ans = 0.0;
scanf("%d", &n);
rep(i, n) scanf("%d %d", &rec[i].t, &rec[i].x);
sort(rec, rec + n);
for (int i = ; i < n; i++) {
ans = max(ans, fabs((double)rec[i].x - rec[i - ].x) / (rec[i].t - rec[i - ].t));
}
printf("Case #%d: %.2lf\n", k++, ans);
}
return ;
}
hdu 5112 A Curious Matt的更多相关文章
- 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) ...
- 水题:HDU 5112 A Curious Matt
Description There is a curious man called Matt. One day, Matt's best friend Ted is wandering on the ...
- 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 5112 (2014北京 水)
题意:有个人在跑步,一直每个时间他所在的位置,求最大速度 #include <iostream> #include <cstring> #include <cstdio& ...
- hdu 5112 (2014北京现场赛 A题)
给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值 Sample Input23 // n2 2 //t v1 13 430 31 52 0 Sample OutputCase #1: 2.0 ...
- HDU 5119 Happy Matt Friends (背包DP + 滚动数组)
题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...
- 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...
随机推荐
- 手游设备ID
android: imei: IMEI(International Mobile Equipment Identity)是国际移动设备标识的缩写,IMEI由15位数字(英文字母)组成. mac: 是指 ...
- BFPRT(线性查找算法)
BFPRT算法解决的问题十分经典,即从某n个元素的序列中选出第k大(第k小)的元素,通过巧妙的分 析,BFPRT可以保证在最坏情况下仍为线性时间复杂度.该算法的思想与快速排序思想相似,当然,为使得算法 ...
- MyEclipse简单设置
1.设置 安装完MyEclipse后,先设置工作空间的编码. Window—preferences—General--workspace—选择UTF-8编码 创建HTML的文件后,如果不是UTF- ...
- docker1.12在cento7里的跨多主机容器网络
docker1.12在cento7里的跨多主机容器网络
- sql case when 多条件
when 'ChangeProductName'= case --联名借姓名 --when a.ChangeProductName is not null then (substr ...
- netlink机制
一.netlink机制简介 netlink是一种基于网络的机制,允许在内核内部以及内核与用户之间进行通信.正式定义见RFC3549.手册见netlink(3)和netlink(7).netlink(3 ...
- 背景图片background-size兼容ie8以下浏览器解决
背景图片不够大,然后就想到用background-size:100%; 测试浏览器的时候发现ie8以下不兼容,图片会自动填充平铺过去,然后出现背景不好看的现象.解决方法: background-ima ...
- JS时间
function checkStartTime(){ var d1 = new Date(); var endTime = document.getElementById("secCreat ...
- git备忘(长久更新)
一直想了解一下git,正好最近的有一个问题就是,实验室写的代码,怎么同步到自己宿舍的笔记本上面来.最开始想用dropbox,但是用VS的人都知道,工程文件里面会给你生成乱七八糟的很多东西,很占空间,d ...
- Windows Phone 开发起步之旅之一 平台环境的搭建
最近大家都在写博客园的技术文章,按耐不住了,也把自己平时学习中遇到和学习到的一些东西写出来,供大家分享也好,自己留个纪念也好,有个可以查看的东西. 言归正传,随着微软对Windows Phone的投入 ...