知道距离时间,求最大速度
结构体,sort排序
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 10010
using namespace std;
struct node{
int first,second;
}a[maxn];
bool cmp(node x, node y)
{
return x.first<y.first;
}
int main()
{
int casen, n;
cin >> casen;
for (int tt = 1; tt <= casen;tt++)
{
cin >> n;
for (int i = 0; i<n; i++)
{
cin >> a[i].first >> a[i].second;
}
sort(a, a + n, cmp);
double tmp, ans;
ans = 0.0;
for (int i = 1; i<n; i++)
{
tmp = (double)(abs(a[i].second - a[i - 1].second ))/ (a[i].first - a[i - 1].first);
if (tmp>ans)
ans = tmp;
}
printf("Case #%d: %.2lf\n", tt, ans);
}
return 0;
}