HDU 6581 Vacation

HDU 6581 Vacation

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K(Java/Others)
Total Submission(s): 2173    Accepted Submission(s): 966

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 li, the head of it is si from the stop-line, and its maximum velocity is vi. The car Tom and Jerry are driving is l0 in length, and s0 from the stop-line, with a maximum velocity of 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≤105,∑n≤2×106), the number of cars.
The next three lines each contains n+1 integers, li,si,vi (1≤si,vi,li≤109). It's guaranteed that si≥si+1+li+1,∀i∈[0,n−1]

 

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

二分时间,最后误差在1e-7内的时候输出答案,具体代码如下

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n;
    double s[100010],l[100010],v[100010],vmn,pos[100010];//pos存的是车子行进一段时间后与终点线的距离,可正可负
    int main()
    {
        while(~scanf("%d",&n))
        {
            vmn=1e10;
            for(int i=0;i<=n;i++)
                scanf("%lf",l+i);//车长
            for(int i=0;i<=n;i++)
               scanf("%lf",s+i);//车头距离终点线的长度
            for(int i=0;i<=n;i++)
                scanf("%lf",v+i),vmn=v[i]<vmn?v[i]:vmn;//车子的速度,并用vmn存最小车速
            if(!n)//如果n=0,即只有一辆车,则直接路程除以时间得出结果
            {
                printf("%.10lf\n",s[0]/v[0]);
                continue;
            }
            double left=0,right=s[0]/vmn;
            //利用二分来查找时间
            while(right-left>=1e-7)
            {
                double mid=(right+left)/2;
                for(int i=n;i>=0;i--)
                    pos[i]=s[i]-v[i]*mid;
                //计算车运行mid时间后相对终点线的距离,可正可负
                for(int i=n-1;i>=0;i--)
                    if(pos[i]<pos[i+1]+l[i+1])//如果后面的车越过前面的车,则把这辆车重新置于后面
                       pos[i]=pos[i+1]+l[i+1];
                if(pos[0]<0)
                    right=mid;
                else left=mid;
                //时间多了左缩区间,时间少了右缩区间 
            }
            printf("%.10lf\n",left); 
        }
        return 0;
    }

 

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值