HDU 5935 Car ###K ###K //K

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5935

题意:给定一些点是经过的点,不知道通过点的时间,并且移动速度是非递减的,求问通过到最后的点所需要的最少时间

思路:直接用速度公式比较 考虑精度的问题 应该用 s1/t1<=s2/t2 来做  然后用t1=s1*t2/s2 向上取整来计算,t和s都是整数不用考虑精度的问题

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define pb push_back
 5 const int maxn =1e5+10;
 6 const int mod=1e9+7;
 7 const double pi=3.1415926535;
 8 #define double long double
 9 ll a[maxn];
10 ll b[maxn];
11 
12 
13 int main()
14 {
15     ios::sync_with_stdio(false);
16     cin.tie(0);
17     int t;
18     cin>>t;
19     int cnt=0;
20     while(t--)
21     {
22         int n;
23         cin>>n;
24         ll ans=1;
25         ll tim=1;
26         for(int i=1;i<=n;i++)
27         {
28             cin>>a[i];
29         }
30         for(int i=1;i<=n;i++)
31         {
32             b[i]=a[i]-a[i-1];
33         }
34 
35         for(int i=n-1;i>=1;i--)
36         {
37             ll x=(b[i]*tim-1+b[i+1])/b[i+1];
38             ans+=x;
39             tim=x;
40         }
41         cout<<"Case #"<<++cnt<<": ";
42         cout<<ans<<'\n';
43 
44     }
45 
46 
47 
48 
49 
50 }
View Code

 

posted @ 2020-10-11 21:10  canwinfor  阅读(63)  评论(0)    收藏  举报