nssl1448-小智过马路【模拟】
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                nssl1448-小智过马路【模拟】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                正題
題目大意
nnn個橫向道,若干輛車,每輛車速度恒定,給出方向位置長度。
過馬路的速度,最早開始時間,最晚開始時間。求最長的可以通過馬路的時間段。
解題思路
計算出每輛車限制的時間區間,然后排序找到一個最長為空的區間。
codecodecode
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> using namespace std; const int N=1e5+10; struct node{double x;int w; }a[N*2]; int n,cnt; double w,u,v,st,tt,ans; bool cmp(node x,node y) {return x.x<y.x;} int main() {scanf("%d%lf%lf%lf%lf%lf",&n,&w,&u,&v,&st,&tt);for(int i=1;i<=n;i++){char op;int m;cin>>op>>m;for(int j=1;j<=m;j++){double l,p,sT,eT;scanf("%lf%lf",&l,&p);if(op=='E') sT=-p/u,eT=(l-p)/u;if(op=='W') sT=p/u,eT=(p+l)/u;if(sT>eT) swap(sT,eT);sT-=i*(w/v);eT-=(i-1)*(w/v);a[++cnt]=(node){sT,1};a[++cnt]=(node){eT,-1};}}sort(a+1,a+1+cnt,cmp);int now=0;ans=max(a[1].x-st,tt-a[cnt].x);for(int i=1;i<cnt;i++){now+=a[i].w;if(now==0)ans=max(ans,min(a[i+1].x,tt)-max(a[i].x,st));}printf("%.8lf",ans); }總結
以上是生活随笔為你收集整理的nssl1448-小智过马路【模拟】的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 鲁山县属于哪个市 风景名胜介绍
 - 下一篇: 初生婴儿用品清单 初生婴儿要准备什么用品