UVa 11627 Slalom 解题报告(二分)

本文介绍了一种通过二分搜索法来确定滑雪比赛中能够通过所有障碍门的最佳滑雪速度的方法。文章详细解释了如何根据给定的赛道布局和限制条件,找到最快完成比赛的滑雪速度。

Problem E: Slalom

You are competing in a ski slalom, and you need to selectthe best skis for the race. The format of the race is that there are Npairs of left and right gates, where each right gate is W metres to the rightof its corresponding left gate, and you may neither pass to the left of the leftgate nor to the right of the right gate. The ith pair of gates occurs atdistance yi down the hill,with the horizontal position of the ith left gategiven by xi. Each gate is further down the hill than theprevious gate (i.e. yi < yi+1 for all i).

You may select from S pairs of skis, where the jth pair has speedsj.Your movement is governed by the following rule: if you select a pair of skiswith speed sj, you move with a constant downward velocity of sjmetres per second.Additionally, at any time you may move at a horizontal speed of at most vhmetres per second.

You may start and finish at any two horizontal positions.Determine which pair of skis will allow you to get through the race course,passing through all the gates, in the shortest amount of time.

Input Specification

The first line of input contains a single integer, the number of test cases to follow.

The first line of each test case contains the three integers W, vh, andN, separated by spaces, with1 <= W <= 108,1 <= vh <= 106, and1 <= N <= 105.

The following N lines of the test case each contain two integers xiandyi, the horizontal and vertical positions respectively of theith left gate, with1 <= xi, yi <= 108.

The next line of the test case contains an integer S, the number of skis,with1 <= S <= 106.

The following S lines of the test case each contain one integer sj, thespeed of the jth pair of skis, with 1 <= sj <= 106.

Sample Input

2
3 2 3
1 1
5 2
1 3
3
3
2
1
3 2 3
1 1
5 2
1 3
1
3

Output Specification

Output one line for each test case.If it is impossible to complete the race with any pair of skis, print the lineIMPOSSIBLE. Otherwise, print the vertical speed sjof the pair of skis that allows you to get through the race course in the shortest time.

Output for Sample Input

2
IMPOSSIBLE


    解题报告: 首先,题意比较难懂。简单来说就是下面这个样子:

    图很烂……黑色的线条代表gate,左边的点的坐标就是(xi, yi)。人从山上y=0的地方滑下来,垂直速度为sj, 水平速度为0 - vh。

    题目让我们求出可以通过所有gate最大速度。思路呢,自然是二分速度了。每次我们求出经过一个gate后,能到达的最左边的位置left,和最右边的位置right。与下一个gate的横坐标进行比较。如果二者有交集,那么说明可以滑进去,修正下左右位置,继续;如果不能,说明垂直速度太快了,需要用更慢的速度去滑,这样水平位移可以更大一点。

    中间求位移的地方没有直接除速度sj,而是让其他变量乘上sj,确保精度。代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <string>
using namespace std;

#define ff(i, n) for(int i=0;i<(n);i++)
#define fff(i, n, m) for(int i=(n);i<=(m);i++)
#define dff(i, n, m) for(int i=(n);i>=(m);i--)
typedef long long LL;
typedef unsigned long long ULL;
void work();

int main()
{
#ifdef ACM
    freopen("in.txt", "r", stdin);
#endif // ACM

    work();
}

/*****************************************/

int x[111111], y[111111];
int spd[1111111];

int w, vh, n;

bool check(int vv)
{
    LL left = (LL)x[0]*vv, right = (LL)(x[0] + w)*vv;

    ff(i, n-1)
    {
        LL len = (LL)(y[i+1]-y[i]) * vh;

        if(left-len > (LL)(x[i+1]+w)*vv) return false;
        if(right+len < (LL)x[i+1]*vv) return false;

        left = max((LL)x[i+1]*vv, left-len);
        right = min((LL)(x[i+1]+w)*vv, right+len);
    }

    return true;
}

void work()
{
    int T;
    scanf("%d", &T);
    ff(cas, T)
    {
        scanf("%d%d%d", &w, &vh, &n);

        ff(i, n) scanf("%d%d", x+i, y+i);

        int s;
        scanf("%d", &s);
        ff(i, s) scanf("%d", spd+i);
        sort(spd, spd+s);
        s = unique(spd, spd+s) - spd;

        int l = 0, r = s - 1;
        while(l <= r)
        {
            int m = (l+r)/2;

            if(check(spd[m]))
                l = m + 1;
            else
                r = m - 1;
        }

        if(r == -1)
            puts("IMPOSSIBLE");
        else
            printf("%d\n", spd[r]);
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值