A Curious Matt
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5112
解题思路:
题目大意:
求出最大的速度。
算法思想:
先将所有的时间排个序,然后依次求出速度,取最大值即可。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
struct node{
int t;
double x;
bool operator < (const node &a) const{
return t < a.t;
}
}no[10005];
int main(){
int T,t = 1;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d%lf",&no[i].t,&no[i].x);
sort(no,no+n);
double ans = 0,tmpv;
for(int i = 1; i < n; i++){
tmpv = fabs(no[i].x-no[i-1].x)/(no[i].t-no[i-1].t);
if(ans < tmpv)
ans = tmpv;
}
printf("Case #%d: %.2lf\n",t++,ans);
}
return 0;
}
102

被折叠的 条评论
为什么被折叠?



