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. MFC输出调试信息

    刚学mfc时只知道用MessageBox输出,可是MessageBox只能输出字符串, 对于习惯于printf的我来说非常不便,后来查了一下mfc可以像printf一样输出, 就是TRACE这个宏,用 ...

  2. 【HackerRank】Manasa and Stones

    Change language : Manasa 和 她的朋友出去徒步旅行.她发现一条小河里边顺序排列着带有数值的石头.她开始沿河而走,发现相邻两个石头上的数值增加 a 或者 b. 这条小河的尽头有一 ...

  3. 摊铺机基本参数介绍(三一重工SSP220C-5)

    三一重工SSP220C-5稳定土摊铺机参数 SSP系列稳定土摊铺机SSP220C-5 动力强劲162kw 动力充分满足摊铺机各种工况下动力需求 高效任何工况,确保摊铺能力大于900t/h,行业内绝无仅 ...

  4. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 是什么意思?

    <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENA ...

  5. 理解Android Build系统【转】

    本文转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-android-build/ Android Build 系统是用来编译 And ...

  6. Service Meth and SideCar

    本文转自:http://philcalcado.com/2017/08/03/pattern_service_mesh.html SideCar: SideCar就是与Application一起运行的 ...

  7. codeforces 439C 模拟

    http://codeforces.com/problemset/problem/439/C 题意:给你n个数,分成k个非空集合,其中有p个集合的元素和为偶数,其余k-p个集合的元素和为奇数. 思路: ...

  8. 音乐下载api

    青檬音乐 http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.5.6&format=js ...

  9. MapReduce-读取文件写入HBase

    MapReduce直接写入HBase 代码如下 package com.hbase.mapreduce; import java.io.IOException; import org.apache.c ...

  10. MapReduce-多个输出(使用MultipleOutput,不指定reduce任务个数)

    多个输出 FileOutputFormat及其子类产生的文件放在输出目录下.每个reduce一个文件并且文件由分区号命名:part-r-00000,part-r-00001,等等.有时可能需要对输出的 ...