• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
镂空的行尸
   首页       联系   管理    订阅  订阅

Teacher Bo (时间复杂度 + 暴力)

如果你仔细看就会发现有一个数据很重要那就是点的范围,那么这样一来最多只有2 * maxn的不同曼哈顿距离了,这样一看只要暴力一下就可以过了。

#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 7;
int x[maxn], y[maxn];
bool cn[maxn * 2];

int cnt(int a, int b){
    return abs(x[a] - x[b]) + abs(y[a] - y[b]);
}

bool solve(int n, int m){
    if(n * (n - 1) > 2 * maxn) return true;
    memset(cn, false, sizeof(cn));
    for(int i = 0; i < n; i ++)
        for(int j = i + 1; j < n; j ++)
            if(cn[cnt(i, j)]) return true;
            else cn[cnt(i, j)] = true;
    return false;
}

int main(){
    int T, n, m;scanf("%d", &T);
    while(T -- ){
        scanf("%d%d", &n, &m);
        for(int i = 0; i < n; i ++)scanf("%d%d", &x[i], &y[i]);
        printf("%s\n", solve(n, m)?"YES":"NO");
    }
    return 0;
}

 

more crazy more get!
posted @ 2018-10-21 02:42  镂空的行尸  阅读(137)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3