「hdu6581」Vacation【思维】

Vacation

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 337 Accepted Submission(s): 103
Special Judge

Problem Description

Tom and Jerry are going on a vacation. They are now driving on a one-way road and several cars are in front of them. To be more specific, there are n cars in front of them. The ith car has a length of l i l_i li, the head of it is s i s_i si from the stop-line, and its maximum velocity is v i v_i vi. The car Tom and Jerry are driving is l 0 l_0 l0 in length, and s 0 s_0 s0 from the stop-line, with a maximum velocity of v 0 v_0 v0.
The traffic light has a very long cycle. You can assume that it is always green light. However, since the road is too narrow, no car can get ahead of other cars. Even if your speed can be greater than the car in front of you, you still can only drive at the same speed as the anterior car. But when not affected by the car ahead, the driver will drive at the maximum speed. You can assume that every driver here is very good at driving, so that the distance of adjacent cars can be kept to be 0.
Though Tom and Jerry know that they can pass the stop-line during green light, they still want to know the minimum time they need to pass the stop-line. We say a car passes the stop-line once the head of the car passes it.
Please notice that even after a car passes the stop-line, it still runs on the road, and cannot be overtaken.

Input

This problem contains multiple test cases.
For each test case, the first line contains an integer n ( 1 ≤ n ≤ 1 0 5 , ∑ n ≤ 2 × 1 0 6 ) n (1\leq n\leq10^5,\sum n\leq 2×10^6) n(1n105,n2×106), the number of cars.
The next three lines each contains n + 1 n+1 n+1 integers, l i , s i , v i ( 1 ≤ s i , v i , l i ≤ 1 0 9 ) l_i,s_i,v_i (1\leq s_i,v_i,l_i\leq 10^9) li,si,vi(1si,vi,li109). It’s guaranteed that s i ≥ s i + 1 + l i + 1 s_i \geq s_{i+1}+l_{i+1} sisi+1+li+1, ∀ i ∈ [ 0 , n − 1 ] \forall i∈[0,n−1] i[0,n1]

Output

For each test case, output one line containing the answer. Your answer will be accepted if its absolute or relative error does not exceed 1 0 − 6 10^{−6} 106.
Formally, let your answer be a, and the jury’s answer is b. Your answer is considered correct if ∣ a − b ∣ m a x ( 1 , ∣ b ∣ ) ≤ 1 0 − 6 \frac {|a−b|}{max(1,|b|)}\leq10^{−6} max(1,b)ab106.
The answer is guaranteed to exist.

Sample Input

1
2 2
7 1
2 1
2
1 2 2
10 7 1
6 2 1

Sample Output

3.5000000000
5.0000000000

Source

2019 Multi-University Training Contest 1

题意

  • 就是给你 n + 1 n+1 n+1个车子,编号从 0 0 0 n n n,开始每辆车的位置为 s i s_i si,长度 l i l_i li,最大速度 v i v_i vi,并且有 s i ≥ s i + 1 + l i + 1 s_i \geq s_{i+1}+l_{i+1} sisi+1+li+1, ∀ i ∈ [ 0 , n − 1 ] \forall i∈[0,n−1] i[0,n1],车道为单向单车道,即后面的车如果追上前面的车子的话,只能以前面车子的速度继续跑,即不能超车,而且如果车子前面没有别的车子挡住他的话,会以最大速度跑,而且车距最小可以为 0 0 0,现在让所有车朝着位置 0 0 0跑,求 0 0 0号车经过位置0的时间

题解

  • 比赛的时候我们想复杂了,当时想着用优先队列维护最先碰撞的车子,然后合并他们,写着写着就自闭了
  • 其实可以这么想,声明连在一起的车子的最前面的那辆车为头车,当 0 0 0号车到达位置 0 0 0时,他的头车已经到达了负数位置处【或位置 0 0 0处,表示他自己就是头车】,可以发现头车没有受其他任何车子影响,他在这个过程中一直以最大速度跑,所以可以枚举头车,计算时间取个 m a x max max就行了

代码

#include<bits/stdc++.h>

using namespace std;
const int maxn=1e5+10;

int n;long long s[maxn],l[maxn],v[maxn],sum[maxn];


namespace IO{ 
    #define BUF_SIZE 100000 
    #define OUT_SIZE 100000 
    #define ll long long 

    bool IOerror=0; 
    inline char nc(){ 
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; 
        if (p1==pend){ 
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); 
            if (pend==p1){IOerror=1;return -1;} 
        } 
        return *p1++; 
    } 
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';} 
    inline bool read(int &x){ 
        bool sign=0; char ch=nc(); x=0; 
        for (;blank(ch);ch=nc()); 
        if (IOerror) return false; 
        if (ch=='-')sign=1,ch=nc(); 
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 
        if (sign)x=-x; return true;
    } 
    inline void read(ll &x){ 
        bool sign=0; char ch=nc(); x=0; 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        if (ch=='-')sign=1,ch=nc(); 
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 
        if (sign)x=-x; 
    } 
    inline void read(double &x){ 
        bool sign=0; char ch=nc(); x=0; 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        if (ch=='-')sign=1,ch=nc(); 
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 
        if (ch=='.'){ 
            double tmp=1; ch=nc(); 
            for (;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0'); 
        } 
        if (sign)x=-x; 
    } 
    inline void read(char *s){ 
        char ch=nc(); 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch; 
        *s=0; 
    } 
    inline void read(char &c){ 
        for (c=nc();blank(c);c=nc()); 
        if (IOerror){c=-1;return;} 
    } 
    //fwrite->write 
    struct Ostream_fwrite{ 
        char *buf,*p1,*pend; 
        Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;} 
        void out(char ch){ 
            if (p1==pend){ 
                fwrite(buf,1,BUF_SIZE,stdout);p1=buf; 
            } 
            *p1++=ch; 
        } 
        void print(int x){ 
            static char s[15],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); 
        } 
        void println(int x){ 
            static char s[15],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); out('\n'); 
        } 
        void print(ll x){ 
            static char s[25],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); 
        } 
        void println(ll x){ 
            static char s[25],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); out('\n'); 
        } 
        void print(double x,int y){ 
            static ll mul[]={1,10,100,1000,10000,100000,1000000,10000000,100000000, 
                1000000000,10000000000LL,100000000000LL,1000000000000LL,10000000000000LL, 
                100000000000000LL,1000000000000000LL,10000000000000000LL,100000000000000000LL}; 
            if (x<-1e-12)out('-'),x=-x;x*=mul[y]; 
            ll x1=(ll)floor(x); if (x-floor(x)>=0.5)++x1; 
            ll x2=x1/mul[y],x3=x1-x2*mul[y]; print(x2); 
            if (y>0){out('.'); for (size_t i=1;i<y&&x3*mul[i]<mul[y];out('0'),++i) {}; print(x3);} 
        } 
        void println(double x,int y){print(x,y);out('\n');} 
        void print(char *s){while (*s)out(*s++);} 
        void println(char *s){while (*s)out(*s++);out('\n');} 
        void flush(){if (p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}} 
        ~Ostream_fwrite(){flush();} 
    }Ostream; 
    inline void print(int x){Ostream.print(x);} 
    inline void println(int x){Ostream.println(x);} 
    inline void print(char x){Ostream.out(x);} 
    inline void println(char x){Ostream.out(x);Ostream.out('\n');} 
    inline void print(ll x){Ostream.print(x);} 
    inline void println(ll x){Ostream.println(x);} 
    inline void print(double x,int y){Ostream.print(x,y);} 
    inline void println(double x,int y){Ostream.println(x,y);} 
    inline void print(char *s){Ostream.print(s);} 
    inline void println(char *s){Ostream.println(s);} 
    inline void println(){Ostream.out('\n');} 
    inline void flush(){Ostream.flush();}
    #undef ll 
    #undef OUT_SIZE 
    #undef BUF_SIZE 
};
using namespace IO;


int main()
{
    while(read(n)){
        for(int i=1;i<=n+1;i++) read(l[i]);
        for(int i=1;i<=n+1;i++) read(s[i]);
        for(int i=1;i<=n+1;i++) read(v[i]);

        sum[1]=0;
        for(int i=2;i<=n+1;i++) sum[i]=sum[i-1]+l[i];
        double ans=0;
        for(int i=1;i<=n+1;i++) ans=max(ans,(sum[i]+s[i])*1.0/v[i]);
        printf("%.10f\n",ans);

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值