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

用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的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. 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 ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [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 ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. libsvm+eclipse(java)的配置以及开发需要设置的内容

    主要参考博客: 1.eclipse + libsvm-3.12 用SVM实现简单线性分类    cnBlog中的主要介绍如何导入jar包的问题. 2.LIBSVM入门解读   CSDN,主要是对LIB ...

  2. ETL应用:一种处理接口的Pro*C实现方法

    2007年,当时项目所有ETL采用C编写,实现了ETL基本功能.当接口很多时,为保证文件获取效率,做好接口可配置:文件维护中经常会出现接口晚到情况,需要有一种方法能将接口晚到信息写入数据库,便于短信告 ...

  3. JavaScript笔记01——数据存储(包括.js文件的引用)

    While, generally speaking, HTML is for content and CSS is for presentation, JavaScript is for intera ...

  4. CentOS 7卸载mariadb安装mysql

    CentOS 7已经将默认集成mariadb而不是mysql,这对于多数还是依赖于mysql的应用来说,需要手动的进行更新. 可能会遇到这样错误,换成MySQL就好了. error 2002 (hy0 ...

  5. get_called_class--后期静态绑定("Late Static Binding")类的名称

    get_called_class--后期静态绑定("Late Static Binding")类的名称 string get_called_class ( void ) 获取静态方 ...

  6. debian内核代码执行流程(三)

    接续<debian内核代码执行流程(二)>未完成部分 下面这行输出信息是启动udevd进程产生的输出信息: [ ]: starting version 175是udevd的版本号. 根据& ...

  7. leetcode刷题3.无重复字符的最长子串

    题目:给定一个字符串,找出不含有重复字符的 最长子串 的长度. 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3. ...

  8. Linux挂载第二块硬盘操作方法

    远程SSH登录上Centos服务器后,进行如下操作 提醒:挂载操作会清空数据,请确认挂载盘无数据或者未使用 第一步:列出所有已挂载磁盘 命令: disk -h [root@gluster_node1 ...

  9. linux学习(rz和sz命令的安装和使用)

    lrzsz的安装 [root@spark1 ~]# yum install lrzsz rz用法 终端直接输入rz,出现文件选择对话框,选择要上传的文件就ok sz用法 下载filename文件: s ...

  10. 【转】一次完整的HTTP请求所经历的7个步骤

    HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1. 建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该 ...