题目位置:
题意:去找平均速度最大的那一段的速度
思路:按时间排下序就OK~
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
struct node
{
int t, x;
}a[10005];
bool cmp(node a, node b)
{
return a.t<b.t;
}
int main()
{
int T, N, k=1;
scanf("%d", &T);
while(T--)
{
scanf("%d", &N);
for(int i=0; i<N; i++)
{
scanf("%d %d", &a[i].t, &a[i].x);
}
sort(a, a+N);
double max = (double)fabs(a[0].x-a[1].x)/(double)(a[1].t-a[0].t);
for(int i=1; i<N; i++)
{
double m = (double)fabs(a[i].x-a[i+1].x)/(double)(a[i+1].t-a[i].t);
if(m>max) max = m;
}
printf("Case #%d: %.2lf\n", k++, max);
}
return 0;
}