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 ...
随机推荐
- Java 集合系列13之 TreeMap详细介绍(源码解析)和使用示例
转载 http://www.cnblogs.com/skywang12345/p/3310928.html https://www.jianshu.com/p/454208905619
- 基于R语言的数据分析和挖掘方法总结——描述性统计
1.1 方法简介 描述性统计包含多种基本描述统计量,让用户对于数据结构可以有一个初步的认识.在此所提供之统计量包含: 基本信息:样本数.总和 集中趋势:均值.中位数.众数 离散趋势:方差(标准差).变 ...
- Js 类型方面的神坑
你有没有遇见过本来好好的一个数组结果 typeof 出来是个 object 的情况,你有没有遇到过非要写个 typeof x === "undefined" 判断未赋值的情况... ...
- Struts2笔记03——架构(转)
原始内容:https://www.tutorialspoint.com/struts_2/basic_mvc_architecture.htm 架构(很重要!尤其是图!) 从一个比较高的层次来看,St ...
- Shell编程之while循环和until循环
一.当型和直到型循环 1.while循环语句 while < 条件表达式 > do 指令... done while循环执行流程对应的逻辑图 2.until循环语句 until < ...
- Squid 正向代理配置
Squid 正向代理配置 1.删除主配置文件重写写入配置 rm -f /etc/squid/squid.conf 2.重新写入配置正向代理 vim /etc/squid/squid.conf # 监听 ...
- jQuery可放大预览的图片滑块
在线演示 本地下载
- python:列表的方法
注意:在列表的类方法一般是没有返回值的,如果将处理过的列表给新变量,新变量是空类型.如:>>>a=[1,2]>>>b=a.append(3)>>> ...
- 获取CPU利用率
#define MB (1024 * 1024) MEMORYSTATUSEX statex; statex.dwLength = sizeof (statex); GlobalMemoryStatu ...
- 聚合 key-value 转为 key-valueList
一个文件A.tmp的内容如下: 10.9.20.1 m1 10.9.20.2 m1 10.9.20.3 m1 10.9.20.1 m2 10.9.20.2 m2 10.9.20.3 m2 想输出格式为 ...