zoukankan      html  css  js  c++  java
  • 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
    ", solve(n, m)?"YES":"NO");
        }
        return 0;
    }
    more crazy more get!
  • 相关阅读:
    5.16欢乐赛
    卢卡斯定理
    noip2017 宝藏
    [JSOI2009]计数问题
    HDU 1160 FatMouse's Speed
    HDU 1260 Tickets
    HDU 1176 免费馅饼
    HDU 1114 Piggy-Bank
    HDU 1074 Doing Homework
    HDU 1069 Monkey and Banana
  • 原文地址:https://www.cnblogs.com/wethura/p/9823799.html
Copyright © 2011-2022 走看看