题意:有标号从0到n的n+1辆车,每辆车离终点的距离为s[i],车长为l[i],速度为v[i],规定不能超车,问何时所有车都能过终点线
n<=1e5,保证
思路:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned int uint; 5 typedef unsigned long long ull; 6 typedef pair<int,int> PII; 7 typedef pair<ll,ll> Pll; 8 typedef vector<int> VI; 9 typedef vector<PII> VII; 10 typedef pair<ll,int>P; 11 #define N 2100000 12 #define M 151000 13 #define fi first 14 #define se second 15 #define MP make_pair 16 #define pi acos(-1) 17 #define mem(a,b) memset(a,b,sizeof(a)) 18 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++) 19 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--) 20 #define lowbit(x) x&(-x) 21 #define Rand (rand()*(1<<16)+rand()) 22 #define id(x) ((x)<=B?(x):m-n/(x)+1) 23 #define ls p<<1 24 #define rs p<<1|1 25 26 const ll MOD=1e9+7,inv2=(MOD+1)/2; 27 double eps=1e-6; 28 ll INF=1e18; 29 ll inf=5e13; 30 int dx[4]={-1,1,0,0}; 31 int dy[4]={0,0,-1,1}; 32 33 int l[N],s[N],v[N]; 34 35 int read() 36 { 37 int v=0,f=1; 38 char c=getchar(); 39 while(c<48||57<c) {if(c==‘-‘) f=-1; c=getchar();} 40 while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar(); 41 return v*f; 42 } 43 44 45 int main() 46 { 47 //freopen("1.in","r",stdin); 48 //freopen("1.out","w",stdout); 49 int n; 50 while(scanf("%d",&n)!=EOF) 51 { 52 rep(i,1,n+1) l[i]=read(); 53 rep(i,1,n+1) s[i]=read(); 54 rep(i,1,n+1) v[i]=read(); 55 double sum=0,ans=1.0*s[1]/v[1]; 56 rep(i,2,n+1) 57 { 58 sum+=l[i]; 59 ans=max(ans,1.0*(sum+s[i])/v[i]); 60 } 61 printf("%.10f\n",ans); 62 } 63 64 65 66 return 0; 67 }
原文:https://www.cnblogs.com/myx12345/p/11438692.html