hdu 5112 (2014北京区域赛 A题)

给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值

Sample Input
2
3 // n
2 2 //t v
1 1
3 4
3
0 3
1 5
2 0

Sample Output
Case #1: 2.00
Case #2: 5.00

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <algorithm>
 5 # include <string>
 6 # include <cmath>
 7 # include <queue>
 8 # include <list>
 9 # define LL long long
10 using namespace std ;
11
12 struct point
13 {
14     int t ;
15     int v ;
16 }a[10010];
17
18 bool cmp(point x , point y)
19 {
20     return x.t < y.t ;
21 }
22
23 int main()
24 {
25     //freopen("in.txt","r",stdin) ;
26     int T ;
27     scanf("%d" , &T) ;
28     int Case = 0 ;
29     while(T--)
30     {
31         int n , i ;
32         Case++ ;
33         double MAX = 0 ;
34         scanf("%d" , &n) ;
35         for (i = 0 ; i < n ; i++)
36            scanf("%d %d" , &a[i].t , &a[i].v) ;
37         sort(a , a+n , cmp) ;
38         for (i = 0 ; i < n-1 ; i++)
39         {
40             double ans = fabs((a[i+1].v - a[i].v)*1.0/(a[i+1].t - a[i].t)*1.0) ;
41             if (ans > MAX)
42                 MAX = ans ;
43         }
44         printf("Case #%d: %.2lf\n" , Case , MAX) ;
45
46     }
47
48     return 0 ;
49 }

时间: 2024-10-24 11:25:59

hdu 5112 (2014北京区域赛 A题)的相关文章

hdu 5122 (2014北京区域赛 K题)

把一个序列按从小到大排序 要执行多少次操作 只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1 Sample Input255 4 3 2 155 1 2 3 4 Sample OutputCase #1: 4Case #2: 1 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5

Heshen&#39;s Account Book HihoCoder - 1871 2018北京区域赛B题(字符串处理)

Heshen was an official of the Qing dynasty. He made a fortune which could be comparable to a whole country's wealth by corruption. So he was known as the most corrupt official in Chinese history. But Emperor Qianlong liked, or even loved him so much

HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)

这题定义了一种新的排序算法,就是把一串序列中的一个数,如果它右边的数比它小 则可以往右边移动,直到它右边的数字比它大为止. 易得,如果来模拟就是O(n^2)的效率,肯定不行 想了一想,这个问题可以被转化成 求这一串序列当中每个元素,它的右边是否存在小于它的数字,如果存在,则++ans 一开始没想到诶= = 不应该不应该 1 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler 2 #include <std

HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)

虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[i]] + dp[i - 1][j]; dp[i][j] 的意思是,对于数列 中前 i 个数字,使得 XOR 和恰好为 j 的方案数 状态转移方程中的 dp[i - 1][j] 即表示当前这个数字不取, dp[i - 1][j ^ a[i]] 表示当前这个数字要取. 这道题还是要好好理解阿! sou

hdu 5137 去掉一个点 使得最短路最大(2014广州区域赛K题)

题意:从2~n-1这几个点中任意去掉一个点,使得从1到n的最短路径最大,如果任意去掉一个点1~n无通路输出Inf. Sample Input4 51 2 31 3 71 4 502 3 43 4 23 21 2 302 3 100 0 Sample Output50Inf 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 #

hdu 5078 2014鞍山现场赛 水题

http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,因为说了ti<ti+1 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include &l

【组队训练】2014北京区域赛

四题,排名107,铜尾.... 发挥还真是稳定阿.... 这场队友终于给力了,我怂了....QAQ A 水题,10min 1A K 水题,28min 2A 还是需要一点点想法的.我傻逼了,错了一次…… #include <cstdio> const int maxn = 3e6 + 10; int T,n; int a[maxn]; int main() { //freopen("in.txt","r",stdin); scanf("%d&qu

[hdu 5032]2014北京网络赛Always Cook Mushroom 离散化+离线线段树/树状数组

Always Cook Mushroom Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 196    Accepted Submission(s): 54 Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-q

HDOJ Osu! 5078【2014鞍山区域赛I题-水】

Osu! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1263    Accepted Submission(s): 660 Special Judge Problem Description Osu! is a very popular music game. Basically, it is a game about cli