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 ...
随机推荐
- openstack ocata版(脚本)计算节点安装
一.初始化环境: 1.安装软件包: yum -y install centos-release-openstack-ocata yum -y upgrade yum -y install python ...
- pyhton3 configparser模块
1 #!/usr/bin/env python 2 # coding=utf-8 3 __author__ = 'Luzhuo' 4 __date__ = '2017/5/26' 5 # config ...
- PAT 天梯赛 L1-027. 出租 【模拟】
题目链接 https://www.patest.cn/contests/gplt/L1-027 题意 给出一串电话号码,找出其中不同数字的个数,并且按递减顺序排列,然后 有一个index 数组,指出每 ...
- 树莓派从 DHT11 温度湿度传感器读取数据
时序图参考厂家说明书:DHT11数字湿温度传感器的原理和应用范例 四个阵脚连接:VCC接3.3伏电源,Dout接GPIO口,我接的是物理12针脚,NC留空,GND接地. 波折1:电阻被错接进了VCC, ...
- ubuntu 12.04.2 基于 L3.0.35_1.1.0_121218_source LTIB 问题汇总
1)解压L3.0.35_1.1.0_121218_source.tar.gz 2)cd L3.0.35_1.1.0_121218_source ,执行./install 3) 复制 patch-l ...
- Qt事件机制---信号通过事件实现,事件可以过滤,事件更底层,事件是基础,信号是扩展。
转:http://www.cnblogs.com/findumars/p/8001484.html Qt事件机制(是动作发生后,一种通知对象的消息,是被动与主动的总和.先处理自己队列中的消息,然后再处 ...
- Qt+数据库
前言支持内置数据库: 一.sqlite 1.在头文件中声明数据库对象 QSqlDatabase db; 2.在构造函数中定义对象(最好这样定义,因为对于db来说只需要addDatabase一次,否则多 ...
- No input clusters found in output/ZS_TEST_OUTPUT3404268420/clusters-0/part-randomSeed. Check your -c argument.
错误原因可能为: -i 后面参数路径对应的目录或文件中的数据为空,即输入集为空,所以找不到cluster
- 字符串处理sdut 2411
题目:http://www.sdutacm.org/sdutoj/problem.php?action=showproblem&problemid=2411 关于字符串处理的题,此题坑点很多w ...
- 【codevs3012+codevs3037】线段覆盖4+线段覆盖5(DP)
线段覆盖4网址:http://codevs.cn/problem/3012/ 线段覆盖5网址:http://codevs.cn/problem/3037/ 题目大意:给出一条直线上的一坨线段,每条线段 ...