hdu 5112 A Curious Matt

来源:互联网 发布:es6 对象转成数组 编辑:程序博客网 时间:2024/05/22 10:43

知道距离时间,求最大速度

结构体,sort排序


#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define maxn 10010using 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;}


0 0
原创粉丝点击