At the Hell's Threshold ( 相似多边形的判断 )

At the Hell's Threshold ( 相似多边形的判断 )

Desmond and Thorwald rush to rescue! They are making their way through the secret underground tunnel, magically connecting the human world with Enia. But the tunnel forks into n passages, each having an ancient elven rune carefully painted above. As you might guess, not all the passages lead to Enia: some of them lead to other worlds, most of which are not suitable for life.

Ancient elven runes are the sets of luminous points, in a certain way arranged relative to each other. Each of the runes denotes the name of the world where the corresponding passage leads, in the ancient elven language. Fortunately, one tavern master had sketched the image of the desired rune on a napkin and gave it to the heroes. The image is made not in full size but is oriented correctly, i.e. from the coordinates of points on the image it is possible to get the coordinates of points on the rune by zoom (equal by all directions) and translation.

Input

The first line contains two integers separated by the space: n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 10000) — the number of passages marked by runes and the number of points each rune made of.

The next lines contains 2m integers each, separated by the spaces: xij and yij ( - 109 ≤ xij, yij ≤  + 109) — the coordinates of the j-th point on the i-th image of the rune. The first image corresponds to tavern master's drawing, and the other n correspond to the runes above passages. For each image, all points on it are different.

Output

Output n lines. In the i-th line output «YES» (without quotes) if the i-th passage leads to Enia, otherwise output «NO» (without quotes) in this line.

Examples

Input

2 3
3 4 4 6 4 5
-100 -200 100 200 100 0
-3 -4 -4 -6 -4 -5

Output

YES
NO

Input

4 4
0 0 1 2 3 6 5 10
1 1 2 3 4 7 6 11
11 21 3 5 7 13 1 1
-1 -2 0 0 4 8 2 4
0 1 1 3 2 5 3 7

Output

YES
YES
YES
NO

题意:给一个目标多边形,告诉每个顶点的坐标,下面n次询问给出的多边形是否和目标多边形相似( 可以扩大缩小,不能旋转 )。

思路:因为多边形给点的时候没有顺序,所以需要自己定义一个顺序,就是代码中的rule函数,让两个多边形的各个点顺序对应起来, 然后我们选择左上角的那个点,所有其他点和他连线,得到x差值,y差值。 如果两个多边形相似,那么这些差值都要一一对应,成倍数关系。

代码:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e4+10;
struct node {
    int x,y;
}a[maxn],b[maxn];

int n,m;

bool rule( node a, node b )
{
    if ( a.x==b.x ) return a.y<b.y;
    return a.x<b.x;
}

int main()
{
    int i,j;
    cin >> n >> m;
    for ( i=0; i<m; i++ ) {
        scanf("%d %d",&a[i].x,&a[i].y);
    }
    sort(a,a+m,rule);
    int g = a[1].x-a[0].x;
    for ( i=1; i<m; i++ ) {
        g = __gcd(g,a[i].x-a[0].x);
        g = __gcd(g,a[i].y-a[0].y);
    }
    while ( n-- ) {
        for ( i=0; i<m; i++ ) {
            scanf("%d %d",&b[i].x,&b[i].y);
        }
        sort(b,b+m,rule);
        int tg = b[1].x-b[0].x;
        for ( i=1; i<m; i++ ) {
            tg = __gcd(tg,b[i].x-b[0].x);
            tg = __gcd(tg,b[i].y-b[0].y);
        }
        int isp = 1;
        for ( i=1; i<m; i++ ) {
            if ( (a[i].x-a[0].x)/g!=(b[i].x-b[0].x)/tg || (a[i].y-a[0].y)/g!=(b[i].y-b[0].y)/tg ) {
                isp = 0;
                break ;
            }
        }
        if ( isp==1 ) cout << "YES" << endl;
        else cout << "NO" << endl;
    }


    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于形态学的图像处理是一种常用的图像处理方法,它可以分析图像的形状、大小和结构等特征,从而实现对图像的分割、去噪、形态学变换等操作。在图像相似判断中,基于形态学的方法可以用于检测和分析图像中的形态学特征,从而实现对图像的相似判断。 以下是一个简单的示例代码,演示如何使用基于形态学的方法判断两张图片是否相似: ```csharp using OpenCvSharp; // 加载原始图像和目标图像 Mat src = Cv2.ImRead("src.jpg", ImreadModes.Color); Mat tpl = Cv2.ImRead("tpl.jpg", ImreadModes.Color); // 转换为灰度图像 Mat src_gray = new Mat(); Mat tpl_gray = new Mat(); Cv2.CvtColor(src, src_gray, ColorConversionCodes.BGR2GRAY); Cv2.CvtColor(tpl, tpl_gray, ColorConversionCodes.BGR2GRAY); // 二值化图像 Mat src_binary = new Mat(); Mat tpl_binary = new Mat(); Cv2.Threshold(src_gray, src_binary, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary); Cv2.Threshold(tpl_gray, tpl_binary, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary); // 进行形态学操作 Mat src_morph = new Mat(); Mat tpl_morph = new Mat(); Mat kernel = Cv2.GetStructuringElement(MorphShapes.Ellipse, new Size(5, 5)); Cv2.MorphologyEx(src_binary, src_morph, MorphTypes.Erode, kernel); Cv2.MorphologyEx(tpl_binary, tpl_morph, MorphTypes.Erode, kernel); // 计算相似度 double similarity = Cv2.MatchShapes(src_morph, tpl_morph, ShapeMatchModes.I1, 0); // 判断是否相似 if (similarity < 0.1) { Console.WriteLine("两张图片相似"); } else { Console.WriteLine("两张图片不相似"); } ``` 在上面的示例中,我们首先将原始图像和目标图像转换为灰度图像,并使用 `Threshold` 函数对其进行二值化处理。然后,我们使用 `MorphologyEx` 函数进行形态学操作,以提取图像的形态学特征。最后,我们使用 `MatchShapes` 函数计算两张图片之间的相似度,并根据相似判断它们是否相似。 需要注意的是,基于形态学的方法对于图像的旋转、缩放等变换比较敏感,如果应用场景需要考虑这些变换,就需要使用更高级的算法,如基于深度学习的图像相似判断

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值