POJ 3258 River Hopscotch

本文探讨了一种策略,通过移除特定数量的石头,来最大化河流上各石头之间的最短跳跃距离。利用二分查找算法,确定最优的石头移除方案,以实现这一目标。
River Hopscotch
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 7836 Accepted: 3370

Description

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).

To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.

Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to rocks (0 ≤ M ≤ N).

FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of Mrocks.

Input

Line 1: Three space-separated integers: LN, and M 
Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.

Output

Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks

Sample Input

25 5 2
2
14
11
21
17

Sample Output

4

Hint

Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).

题目大意:已知一条河宽度为 l ,左右岸各一颗石头,n颗石头与左岸的距离,需要移除m颗石头,使得各石头之间距离的最小值尽量大,求出该最小距离。

解题思路:二分查找,以最大距离为变量,符合条件的移除石头的个数与m比较作为判断条件。写判断条件时,
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=50010;
int a[maxn];
int b[maxn];
int main()
{
    int i,l,n,m,t,num,ans=0;
    int high,low,mid;
    scanf("%d%d%d",&l,&n,&m);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
	sort(a,a+n);
    a[n++]=l;
    low=0;
    high=l;
    while(low<=high)
    {
        mid=(high+low)/2;
        b[0]=0;
        t=0,num=0;  //num为本次循环状态下移除石头的个数
        for(i=0;i<n;i++)
        {
            if(a[i]-b[t]<mid) //两石头之间距离小于mid,则中间石头可以移除
                num++;
            else
                b[++t]=a[i];  
        }
        if(num<=m)  //mid值要尽量大
		{
            low=mid+1;
			ans=mid;
		}
        else
            high=mid-1;
    }
    printf("%d\n", ans);
    return 0;
}

注意mid值要尽量大。

代码如下:
内容概要:本文介绍了一个针对电力系统连锁故障传播路径的N-k多阶段双层优化及故障场景筛选模型,该模型基于混合整数线性规划(MILP)方法构建,旨在全面评估电力系统在遭受多重故障时的脆弱性与恢复能力。通过引入故障传播路径的概念,模型能够动态模拟故障在电网中的逐级扩散过程,并结合多阶段优化策略,实现对关键故障场景的有效识别与优先排序。整个框架不仅考虑了初始故障元件的选取,还涵盖了后续因潮流转移引发的级联跳闸行为,从而提升了风险评估的准确性与时效性。该研究已在Matlab平台上完成代码实现,具备良好的可复现性和工程应用价值,适用于提升现代电网的安全防御水平。; 适合人群:电力系统、能源安全及相关领域的科研人员、高校研究生以及从事电网规划与运行管理的工程技术人员。; 使用场景及目标:①用于电力系统安全评估中识别最危险的N-k故障组合;②支撑电网应急预案制定与薄弱环节改造;③作为学术研究中关于级联故障建模与优化求解的教学与验证工具;④服务于智能电网背景下抵御蓄意攻击或极端事件的风险防控决策。; 阅读建议:建议读者结合Matlab代码深入理解模型的数学 formulation 与求解流程,重点关注目标函数设计、约束条件构建及双层优化结构的实现逻辑,同时可通过调整系统参数和故障设定进行仿真对比分析,以掌握不同因素对连锁故障演化的影响规律。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值