题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112
解题报告:扫一遍
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 const int maxn = 1e6+5; 8 9 struct node 10 { 11 double t,x; 12 }rec[maxn]; 13 double Max(double a,double b) 14 { 15 return a > b? a : b; 16 } 17 bool cmp(node a,node b) 18 { 19 return a.t < b.t; 20 } 21 double Fabs(double d) 22 { 23 return d > 0? d:-1.0*d; 24 } 25 int main() 26 { 27 int T,n,kase = 1; 28 scanf("%d",&T); 29 while(T--) 30 { 31 scanf("%d",&n); 32 for(int i = 0;i < n;++i) 33 scanf("%lf%lf",&rec[i].t,&rec[i].x); 34 sort(rec,rec+n,cmp); 35 double ans = 0; 36 for(int i = 1;i < n;++i) 37 ans = Max(ans,Fabs(rec[i].x-rec[i-1].x) / (rec[i].t - rec[i-1].t)); 38 printf("Case #%d: %.2lf\n",kase++,ans); 39 } 40 return 0; 41 }
时间: 2024-10-06 03:13:02