-
Notifications
You must be signed in to change notification settings - Fork 0
/
1870.cpp
47 lines (44 loc) · 843 Bytes
/
1870.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
bool solve(int mid, vector<int> &dist, double hour)
{
int n = dist.size();
double ans = 0;
for (int i = 0; i < n - 1; i++)
{
float temp = float(dist[i]) / mid;
ans = ans + ceil(temp);
}
ans += float(dist[n - 1]) / mid;
if (ans <= hour)
{
return true;
}
return false;
}
int minSpeedOnTime(vector<int> &dist, double hour)
{
int n = dist.size();
int l = 0;
int h = 1e7;
int res = -1;
while (l <= h)
{
int mid = l + (h - l) / 2;
if (solve(mid, dist, hour))
{
res = mid;
h = mid - 1;
}
else
{
l = mid + 1;
}
}
return res;
}
int main()
{
vector<int> v = {1, 9};
cout << minSpeedOnTime(v, 1.18) << endl;
}