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题,看来单挑只能拿拿铜牌,呜呜. ...
随机推荐
- QTP动态加载对象库
Public Function AddObjectRepository(path) On Error Resume Next Dim pos, repath If instr(path,". ...
- nginx 配置.json文件直接访问
不要弹出下载 配置nginx.conf http { include mime.types; default_type application/json;
- c#中如何做日期的三元判断(日期不为空赋值)
<dx:ASPxDateEdit runat="server" ID="edTab4_protocoldate" Width="100%&quo ...
- 智能指针(一):STL auto_ptr实现原理
智能指针实际上是一个类(class),里面封装了一个指针.它的用处是啥呢? 指针与内存 说到指针自然涉及到内存.我们如果是在堆栈(stack)中分配了内存,用完后由系统去负责释放.如果是自定义类型,就 ...
- ENVI如何打开IRS P6的AWIFS的ges及LISS3的ges文件?
AWIFS文件下文件名如下:ID2010236001.hdrID2010236001_2.gesID2010236001_3.gesID2010236001_4.gesID2010236001_5.g ...
- Completely change MACE timestamps?
Hi, One of my friends Sandy asked me about the possibility of completely change MACE timestamps. As ...
- oracle 创建修改 job
---停止job 25是建立的job begin dbms_job.broken(,true); commit; end; --启动job begin dbms_job.run(); commit; ...
- Java Excel POI
1.使用 String toFileName = "E:\\sheet1.xlsx"; String fromFileName = "E:\\sheet2.xlsx&qu ...
- 免费在线CAD文件转换
AnyCAD Exchange Cloud 提供在线的CAD文件转换服务,包括二维图纸和三维模型的数据转换. 支持的格式有: DWG/DGN/DXF 到 PDF, SVG, DAE等的转换 STEP/ ...
- CentOS6.5 python 2.6升级到2.7
在CentOS6.5下,将自带的python2.6.6升级到python2.7.3,解决方法如下: 下载python2.7.3包,并解压缩,输入命令:#wget http://python.org/f ...