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题,看来单挑只能拿拿铜牌,呜呜. ...
随机推荐
- 阿里云搭建LAMP环境详细教程
一.云服务器的选择 随着大数据时代的到来,为了满足更为复杂的运算和用户更为苛刻的需求,云计算应运而生,随之而来的就是云服务器.过去的服务器成本较高,运算模式较为单一,资源利用率不高,而云服务器的出现刚 ...
- asp.net(c#)中如何在前端用js写条件查询,且不用调用存储过程
前端页面(源): <dx:ASPxButton ID="ASPxButton_Select" runat="server" Text="查询&q ...
- javascript设计模式-工厂模式
简单工厂模式:使用一个类来生成实例. 复杂工厂模式:使用子类来决定一个成员变量应该是哪个具体的类的实例. 简单工厂模式是由一个方法来决定到底要创建哪个类的实例, 而这些实例经常都拥有相同的接口.通过工 ...
- Nodejs笔记(二)
Nodejs事件 Node.js 所有的异步I/O 操作在完成时都会发送一个事件到事件队列. Node.js里面的许多对象都会分发事件:一个net.Server对象会在每次有新连接时分发一个事件, 一 ...
- VC与JavaScript交互(三) --- CWebPage类调用javascript函数(给js函数传参,并取得返回值)
①需要一个别人写好的类CWebPage,将其对于的两个文件WebPage.h和WebPage.cpp添加到工程中. ②添加WebBrowser控件,在视图/对话框类的头文件中#include &quo ...
- Leetcode048. Rotate Image
//鬼晓得上下反转,对角翻转之后竟然正好顺时针九十度,数学事体育老师教的class Solution { public: void rotate(vector<vector<int> ...
- 2016-03-15:关于VS中模块定义文件
1 def模块定义文件 在使用开源库libx265时,因x265项目的头文件x265中有如下的宏定义 #ifdef X265_API_IMPORTS #define X265_API __declsp ...
- centos6 pxe minimal install
# 01-78-2b-cb-69-10-f3 default menu.c32 prompt 0 timeout 100 LABEL centos-6 MENU DEFAULT MENU LABEL ...
- 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(四)-- Middleware
本文记录了Asp.Net管道模型和Asp.Net Core的Middleware模型的对比,并在上一篇的基础上增加Middleware功能支持. 在演示Middleware功能之前,先要了解一下Asp ...
- linux下怎么编译运行C语言程序?
linux下的C语言编译器是gcc,C++的编译器是g++. linux下编程可以使用编辑器vi或vim,建议使用vim,因为它有语法高亮显示.程序编写好后,假设你的程序名为test.c,可以使用gc ...