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
4 2
0 0
0 2
2 2
2 0
4 4
YES
1 -1 2 -1
6 3
0 0
1 0
1 1
2 1
2 2
0 2
3 2 3
YES
1 -1 2 -1 3 -1
6 3
0 0
1 0
1 1
2 1
2 2
0 2
2 2 3
NO 用rods把nails框起来,每个rod只能折叠一次,所以如果一个rod在第i个nail处折叠,那么第i+1个就不是折叠的,nail按顺序给出,只需要枚举奇数或者偶数点,看是否满足,注意初始条件。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#define Max 505
using namespace std;
int x[Max],y[Max],rod[Max],ans[Max];
bool vis[Max],flag;
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i = ;i < n;i ++)
{
scanf("%d%d",&x[i],&y[i]);
}
for(int i = ;i < m;i ++)
{
scanf("%d",&rod[i]);
}
for(int i = ;i < ;i ++)
{
memset(ans,-,sizeof(ans));///方便输出(没有折叠就输出-1) 和 判断是否折叠
memset(vis,false,sizeof(vis));
flag = true;
for(int j = i;j < n;j += )
{
int d = (abs(x[j] - x[(j + n - ) % n]) + abs(y[j] - y[(j + n - ) % n])) + (abs(x[j] - x[(j + ) % n]) + abs(y[j] - y[(j + ) % n]));///前一个钉子到这个钉子以及后一个钉子到这个钉子的距离
for(int k = ;k < m;k ++)
{
if(rod[k] == d && !vis[k])
{
vis[k] = true;
ans[j] = k + ;
break;
}
}
if(ans[j] == -)
{
flag = false;
break;
}
}
if(flag)break;
}
if(!flag)printf("NO");
else
{
printf("YES\n%d",ans[]);
for(int i = ;i < n;i ++)
printf(" %d",ans[i]);
}
}
Bender Problem的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- 交叉编译Mesa,X11lib,Qt opengl
记录Mesa配置文件如下: Mesa版本:Mesa-10.2.3 CC=/usr/local/arm-4.8.1/bin/arm-none-linux-gnueabi-gcc CXX=/usr/loc ...
- nand flash详解及驱动编写
https://www.crifan.com/files/doc/docbook/linux_nand_driver/release/html/linux_nand_driver.html#nand_ ...
- JVM原理(Java代码编译和执行的整个过程+JVM内存管理及垃圾回收机制)
转载注明出处: http://blog.csdn.net/cutesource/article/details/5904501 JVM工作原理和特点主要是指操作系统装入JVM是通过jdk中Java.e ...
- 20145230《java学习笔记》第十周学习总结
20145230<Java程序设计>第十周学习总结 教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或 ...
- 20145240 《Java程序设计》第十周学习总结
20145240 <Java程序设计>第十周学习总结 教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情就是把数据发送到指定的位置 ...
- 20145240 《Java程序设计》第五周学习总结
20145240 <Java程序设计>第五周学习总结 教材学习内容总结 语法与继承结构 8.1.1使用try.catch java中所有的错误都会被打包为对象,并提供了特有的语句进行处理. ...
- 机器学习相关知识整理系列之三:Boosting算法原理,GBDT&XGBoost
1. Boosting算法基本思路 提升方法思路:对于一个复杂的问题,将多个专家的判断进行适当的综合所得出的判断,要比任何一个专家单独判断好.每一步产生一个弱预测模型(如决策树),并加权累加到总模型中 ...
- Python根据内嵌的数字将字符串排序(sort by numbers embedded in strings)
import re re_digits = re.compile(r'(\d+)') def embedded_numbers(s): pieces = re_digits.split ...
- 织梦dedecms 自带采集的缩略图地址后面有“/”斜杠的解决方法
本来想偷懒在网上找一些文档去解决织梦采集缩略图地址带“/”的问题的,可是找了找发现没有人写出解决方法,只好自己动手了. 过程很复杂,找了问题的原因也是找了半天,自己一点一点的测试.最后找到了问题所在. ...
- C#将字符转换成utf8编码 GB321编码转换
public static string get_uft8(string unicodeString) { UTF8Encoding utf8 = new UTF8Encoding(); Byte[] ...