Bender Problem

整数benders分解算法 类比经典的benders分解算法,即子问题包含在原始问题(原问题)中,因此子问题的求解信息与原问题是同步的。(1)子问题假如不可行,那么原问题也不可行;(2)子问题可行,那么原问题也可行;(3)子问题无界,那么原问题也无界。因为子问题不可行,原问题不可行,没有优化的意义,因此我们不需要考虑这种情况。需要考虑的是后两种。(这是经典benders分解中的内容)我们需要考虑的是子问题可行以及子问题无界的情形,即返回最优割和可行割的情形。那么现在的问题变为了对偶问题如何与子问题建立联系? 阅读详情

Bender Problem


Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.

Help Bender to solve this difficult task.

Input

The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers — the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.

Output

If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.

If there are multiple solutions, print any of them.

Example
Input
4 2
0 0
0 2
2 2
2 0
4 4
Output
YES
1 -1 2 -1 
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
3 2 3
Output
YES
1 -1 2 -1 3 -1 
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
2 2 3
Output
NO


这道题主要是题意比较难理解。

题意:有n个钉子,从1~n编号,有m条铁棒,要求用这些铁棒和钉子围成一个封闭的折线。要求铁棒不一定全部用完,铁棒必须平行于坐标轴(这句话说明所有钉子的位置,两两之间的连线一定也是平行于坐标轴的)。现在他要把铁棒完成直角,这样中间的折叠点一个钉子,两头各一个钉子,要求折叠的这颗钉子之前必须是没有别的棒连接的(也就是空钉子),问怎么选棒,棒只能用一次

思路:首先会发现每段会占用三个钉子,而折叠点处需要的钉子是最特殊的,所以我们应该枚举折叠点处的钉子,我们假设折叠点处是i号钉子,那么两头就是i-1号和i+1号钉子,这样i-1到i到i+1的最短折线距离是所需要的棒的长度,所以用两重循环先枚举折叠点,然后算出所需棒的长度,再从所有棒中找恰好等于这个长度的棒有没有

具体怎么枚举:我们发现如果第一个折叠点在1号钉子处,那么下一个折叠点应该在3号,5,7,9……,如果第一个折叠点在2号钉子处,之后的折叠点应该在4,6,8……,所以枚举两次,如果从1开始枚举可以围成封闭折线直接输出,否则在从2开始枚举,如果都不行就说明不可以,反之输出答案。

code:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int MAXN = 505;
int n,m;
struct nail{
    int x,y;
}a[MAXN];
int len[MAXN];
int vis[MAXN];
int ans[MAXN];

int judge(int i,int j){
    return len[j] == ((abs(a[i-1].x-a[i].x)+abs(a[i-1].y-a[i].y))+(abs(a[i+1].x-a[i].x)+abs(a[i+1].y-a[i].y)));
}
void print(){
    int i;
    puts("YES");
    for(i = 1; i <= n; i++){
        if(i == 1)
            printf("%d",(ans[i]?ans[i]:-1));
        else
            printf(" %d",(ans[i]?ans[i]:-1));
    }
}

int main(){
    int i,j;
    int flag,t = 0;
    memset(vis,0,sizeof(vis));
    memset(ans,0,sizeof(ans));
    scanf("%d%d",&n,&m);
    for(i = 1; i <= n; i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    for(i = 1; i <= m; i++)
        scanf("%d",&len[i]);
    a[0].x = a[n].x;
    a[0].y = a[n].y;
    a[n+1].x = a[1].x;
    a[n+1].y = a[1].y;
    for(i = 1; i <= n; i += 2){//从1开始枚举折叠点
        flag = 0;
        for(j = 1; j <= m; j++){
            if(!vis[j] && judge(i,j)){
                flag = 1;
                vis[j] = 1;
                ans[i] = j;
                break;
            }
        }
        if(!flag){
            t = 1;
            break;
        }
    }
    if(!t){//如果符合输出答案
        print();
    }
    else{//否则从二开始枚举折叠点
        memset(vis,0,sizeof(vis));
        memset(ans,0,sizeof(ans));
        for(i = 2; i <= n; i += 2){
            flag = 0;
            for(j = 1; j <= m; j++){
                if(!vis[j] && judge(i,j)){
                    flag = 1;
                    vis[j] = 1;
                    ans[i] = j;
                    break;
                }
            }
            if(!flag){
                printf("NO\n");
                return 0;
            }
        }
        print();
    }
    return 0;
}


Large scale linear optimization 同步发文在 知乎 本文介绍大规模线性规划问题的求解思想。内容主要来源自 《Introduction to Linear Optimization》Chapter 6. Delayed column generation 考虑一个非退化的线性规划的标准问题: min⁡cTxs.t.Ax=b,x≥0(1) \begin{array}{cl} \min & c^T x \\ \text{s.t.} & Ax = b, x \geq 0 \end{array}\tag{1} mins.t.​c 阅读详情

相关推荐

雅思听力词组总结

雅思听力词组总结(涵盖几乎所有雅思真题词组)已更新至1037条

weixin_69884785的博客 2541

Benders分解算法详解

前言 最近在学习Benders Decomposition,看了不少的文章博客,但我感觉写的都不是很清楚,细节地方解释的也不够到位,于是就去读了英文论文原文,发现原文写的还是相当清楚的。本文也基于那篇论文,对Benders Decomposition进行总结。 背景 Benders Decomposition由Jacques F. Benders提出,用来求解混合整数规划问题(MIP:Mixed Integer Programming problem),即同时包含整数和连续变量的极值问题,换句话说就是线性规

qq_42756072的博客 4万+

rk3326 MIPI休眠唤醒黑屏有背光问题

** 1.问题现象: ** **【开机起来】**开机起来可以正常显示 **【按power按键休眠】**第二次按下Power按键进入休眠,隔10s,再按Power按键唤醒。 **【出现结果】**屏幕黑屏有背光,并提示drm time out错 **【lcd信息】**lcd为480*800 2lane的mipi **【复现概率】**第二次按下休眠唤醒必然复现 【具体错误log如下】 //第一次休眠的log// [ 54.858511] dw-mipi-dsi ff450000.dsi: final DSI-

Ian22l的博客 3944

运筹系列7:大规模线性规划的Benders/DW分解

1. 行生成算法 行生成就是指的不断添加约束的算法。 因为在求解矩阵中,一个约束条件对应一行,因此添加约束条件的方法自然叫做行生成算法。相对应的,添加变量的方法就叫做列生成算法。 这一节先看行生成算法,用在求解变量不多,但是约束条件特别多的情况下。 2. Benders分解 Benders分解(Benders Decomposition,BD)的基本思路是:使用子问题(primal ...

kittyzc的博客 3万+

HBuilderX远程开发环境配置:Windows SSH连接实操

详细介绍如何在Windows系统中通过SSH连接远程服务器,配置HBuilderX进行高效远程开发,提升编码协作效率。全程实操演示,轻松掌握hbuilderx与远程环境的无缝对接。

weixin_35751194的博客 1190

OTN设备核心知识速记

本文章为工作笔记,若有错误,还需大家指正。不定期更新。

Hiddengold的博客 2648

Bender Problem(翻译)

来源:https://codeforces.com/contest/28/problem/A Bender Problem Robot Bender decided to make Fray a birthday present. He drovennails and numbered them from1tonin some order. Bender decided to make a picture using metal rods. The picture is a closed p...

qq_61838780的博客 216

超详细!新手必看STM32-DMA配置与实验(串口使用DMA发送数据)

DMA就是:直接存储器访问。DMA传输数据从一个地址空间复制到另一个地址空间,提供在外设和存储器或者存储器和存储器之间的高速数据传输。

qq_1033275663的博客 2万+

简单轻松理解Benders分解算法

Benders分解法是一种用于求解大规模混合整数规划(MIP)或线性规划(LP)问题的数学优化技术,由Jacques F. Benders于1962年提出。其核心思想是将原问题分解为主问题和子问题,通过迭代交换信息(如Benders割)逐步逼近最优解。Benders分解算法的精妙之处在于引入了复杂变量(complicating variables),当这些变量固定后,剩下的优化问题(通常称为子问题)变得相对容易。具体操作是先把复杂变量(整数变量)的值固定,则问题成为一般的线性规划问题。

2302_80918188的博客 3172

abaqus wcm插件下载_Abaqus随机短纤维增强复合材料建模插件

文末附Abaqus随机短纤维增强复合材料建模插件下载链接前言短纤维增强复合材料相对于长纤维增强复合材料来说更容易制备,且短纤维的填充性能略有改善,可制造复杂产品,广泛应用于车辆、航空航天、建筑等行业,对短纤维增强复合材料进行细观力学分析,可对其宏观力学性能进行预测、分析破坏机理等。接下来对随机短纤维增强复合材料建模插件进行介绍。NO.1 【算法简介】难点一:此插件核心在于判断生成的纤维是...

weixin_39974882的博客 2832

SAP 销售订单BOM使用场景简介

通常在MTO的生产场景中,我们会根据已创建的SO去展开BOM去驱动生产,如果我们生产地产品BOM是通用性的通常我们用标准BOM的方式就可以实现,但是实际在生产过程中往往不会这样,不同的客户对某些物料的规格就不相同,就会涉及产生不同的BOM,但是该客户的产品又不存在通用性,这个时候就会引入概念就是销售订单BOM,先有销售订单然后根据销售订单+行项目创建BOM。销售BOM:根据销售订单号+行项目号创建的BOM,是根据特定的销售订单或者可以理解为特定的客户创建的BOM。

我小时候很黑的博客 4216

[codeforces28A]Bender Problem

time limit per test : 2 seconds memory limit per test : 256 megabytes Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to nnn in some order. Bender decid...

dxyinme-Zz 424

25、量子计算:中性原子与约瑟夫森结量子比特

本文详细探讨了中性原子和约瑟夫森结两种量子比特在量子计算中的应用。中性原子量子比特利用光晶格实现量子态的操控,具有长相干时间的优势,但面临可扩展性和多量子比特操作的挑战;而约瑟夫森结量子比特基于超导技术,结合半导体制造工艺,具有低耗散和潜在的高可扩展性,但在参数控制和环境干扰方面存在难题。文章还比较了这两种方案的性能、应用场景及未来发展趋势,展望了它们在量子计算发展中的潜力与突破方向。

ol789012的博客 211

【multimap/pair/数组】#28 A. Bender Problem

看到一道好长的题我主要是比较懒的看题, 然后我就看到了这么些看起来好吓人的解题报告: A. Bender Problem Solution by Polichka Let's look at the first nail. If it is occupied by the fold place, then Bender will put next fold place on the t

CD's Coding 1106

UG\NX二次开发 判断对象是虚线还是实线

网友提问“怎么区分虚线实线”,这个可以通过函数判断。

王牌飞行员_里海的博客 357

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

UVA11507 Bender B. Rodríguez Problem【模拟+时序机+位运算】

Bender is a robot built by Mom’s Friendly Robot Company at its plant in Tijuana, Mexico in 2996. He is a Bending-Unit 22, serial number 2716057 and chassis number 1729. He was created for the task of ...

海岛Blog 776

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

UVa11507 - Bender B. Rodríguez Problem

Bender B. Rodríguez Problem  Bender is a robot built by Mom's Friendly Robot Company at its plant in Tijuana, Mexico in 2996. He is a Bending-Unit 22, serial number 2716057 and chassis n

多看多听多总结 1235

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

CodeForces - 28A Bender Problem【水题】

题目链接:https://codeforces.com/contest/28/problem/A #include <iostream> #include <cmath> #include <cstring> using namespace std; typedef double db; static const int MAXN=500+10; static const db EPS=1e-10; struct Point{ int x,y; void

inv0ker的博客 368

UVa 11507 Bender B. Rodríguez Problem (模拟&异或)

11507 - Bender B. Rodríguez Problem Time limit: 4.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2502 Bender is a robot bui

AC,∑ndless 1435

UVa 11507 - Bender B. Rodríguez Problem

題目:在一個三維空間中,有一條沿著x軸正向傳播的射線長度為L,存在L-1個拐點,             可以向上下左右四個方向偏轉(可以不偏轉,如果數據為No),問最後射線的方向。 分析:模擬。直接打表計算每次轉化后,對應的新的四個方向,模擬計算即可。 說明:和以前寫的魔方變換程序很像╮(╯▽╰)╭。 #include #include int L[100001]; // +x:

小白菜又菜 888

CF28B pSort 解题报告

CF28B pSort 解题报告 1 题目链接 https://codeforces.com/problemset/problem/28/B 2 题目整理 题目 :pSort 题目描述 有一天,某个数组的nnn个单元格决定玩下面的游戏。最初,每个单元格包含一个数字,这个数字等于它的序数(从111开始)。同时,每个单元格也确定了它最喜欢的数字。如果∣i−j∣=di|i - j| = d_i∣i−j∣=di​,其中did_idi​是第iii个单元格的最喜欢的数字,则第iii个单元格可以与其他第jjj个单元格交换

qq_61768466的博客 4932

交通 | 应用Benders分解方法解决多车生产路由问题

为工厂附近长度为lll的离散规划周期的所有顾客提供单一货物。在每个周期开始的时候,生产工厂可以生产最多CCC单位的产品,其中固定支出是fff,单位产品支出是uuu。节点ii∈Ni,i\in Nii∈N有LiL_iLi​单位的仓库容量以及一个库存单位支出hih_ihi​。节点iii最开始在规划区域持有的产品数量为Ii0I_{i0}Ii0​。顾客i∈Nci\in N_ci∈Nc​在周期ttt需要ditd_{it}

weixin_53463894的博客 1287

窄脉冲matlab实现,matlab实现最优脉冲轨道转移

Optimal Impulsive Orbital TransferPDF document and MATLAB script called oota_matlab.m that can be used to determine optimum one and two impulse orbital transfers between non-coplanar circular and elli...

weixin_39874379的博客 320

20260719 LCA(最近公共祖先)算法全景总结报告

LCA(最近公共祖先) 算法总结报告,从简单到复杂,十种算法以及C++实现方案。 配上一个可视化网站。

weixin_51184047的博客 1050
上一篇: Hotaru's problem HDU - 5371 (Manacher+枚举)
下一篇: Equation (分类讨论)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值