题意
传送门 HDU 5112
题解
按时间排序,顺序计算节点间速度,更新答案即可。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 1000005
struct p
{
int t, x;
} ps[maxn];
bool cmp(const p &a, const p &b)
{
return a.t < b.t;
}
int main()
{
int c, n;
scanf("%d", &c);
for (int k = 1; k <= c; k++)
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d%d", &ps[i].t, &ps[i].x);
}
sort(ps, ps + n, cmp);
double res = 0;
int t = ps[0].t, x = ps[0].x;
for (int i = 1; i < n; i++)
{
int t2 = ps[i].t, x2 = ps[i].x;
res = max(res, abs((double)(x2 - x) / (t2 - t)));
t = t2, x = x2;
}
printf("Case #%d: %.2lf\n", k, res);
}
return 0;
}