HDU5762 Teacher Bo

題目連接:http://acm.hdu.edu.cn/showproblem.php?pid=5762


【題意】有n個點,問是否有兩組點的曼哈頓距離相同,兩組點間至少有一個點不同。


【分析】題目限定點的座標範圍,不同曼哈頓距離的最大數量是2*M,所以直接暴力求所有曼哈頓距離即可,最糟糕能在第2*M+1的時候找到相同的值。


【代碼】

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct Node{
    int x,y;
}node[100100];
int re[200200];
int T,n,m;
bool solve(){
    memset(re,0,sizeof(re));
    for(int i=0;i<n;++i)
        for(int j=i+1;j<n;++j){
            int tmp=0;
            tmp+=abs(node[i].x-node[j].x)+abs(node[i].y-node[j].y);
            if(re[tmp])
                return true;
            re[tmp]=1;
        }
    return false;
}
int main(){
    cin>>T;
    while(T--){
        cin>>n>>m;
        for(int i=0;i<n;++i)
            scanf("%d %d",&node[i].x,&node[i].y);
        if(solve())
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章