http://acm.hdu.edu.cn/showproblem.php?pid=5112

 

输入n个时刻和位置,问那两个时刻间速度最快。

 

解法:按照时间排序,然后依次求相邻两个之间的速度,速度=ds/dt

 

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 const int M=1e4+10;
 5 struct G{
 6     int t,x;
 7     friend bool operator <(const G &a,const G &b){
 8         return a.t<b.t;
 9     }
10 }g[M];
11 int main(){
12     int t,n;
13     while(~scanf("%d",&t)){
14         int cas=1;
15         while(t--){
16             scanf("%d",&n);
17             for(int i=0;i<n;i++){
18                 scanf("%d%d",&g[i].t,&g[i].x);
19             }
20             sort(g,g+n);
21             double ans=0;
22             for(int i=0;i<n-1;i++){
23                 ans=max(ans,abs(g[i].x-g[i+1].x)*1.0/(g[i+1].t-g[i].t));
24             }
25             printf("Case #%d: %.2f\n",cas++,ans);
26         }
27     }
28     return 0;
29 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-06-29
  • 2022-12-23
  • 2021-07-23
  • 2022-01-14
猜你喜欢
  • 2021-09-11
  • 2022-01-04
  • 2021-09-19
  • 2021-08-01
  • 2021-09-28
  • 2021-07-18
  • 2021-11-03
相关资源
相似解决方案