HDU5762[Teacher Bo]--暴力枚举

【链接】
hdu5762

【题目大意】

应该很好读懂吧

【解题报告】

由题目意思可知只要判断两个点之间的曼哈顿距离是否在之前出现过即可,因为坐标范围只有 105 ,所以最大的曼哈顿距离只有 2105 ,所以直接暴枚就可以了,复杂度 O(T2105)

#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=200005;
int T,n,m;
bool vis[maxn];
struct Point
{
    int x,y;
}a[maxn];
inline int Read()
{
    int res=0;
    char ch=getchar();
    while (ch<'0'||ch>'9') ch=getchar();
    while (ch>='0'&&ch<='9') res=res*10+ch-48,ch=getchar();
    return res;
}
int Abs(int x) {if (x<0) return (-x); return x;}
void Work()
{
    n=Read(); m=Read(); bool pd=0;
    for (int i=1; i<=n; i++) a[i]=(Point){Read(),Read()};
    memset(vis,0,sizeof(vis));
    for (int i=1; i<n; i++)
    {
        for (int j=i+1; j<=n; j++)
        {
            int k=Abs(a[i].x-a[j].x)+Abs(a[i].y-a[j].y);
            if (vis[k]) {pd=1; break;} else vis[k]=1;
        }
        if (pd) break;
    }
    if (pd) printf("YES"); else printf("NO"); putchar(10);
}
int main()
{
    freopen("5762.in","r",stdin);
    freopen("5762.out","w",stdout);
    T=Read();
    while (T--) Work();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值