zoukankan      html  css  js  c++  java
  • 【模拟】HDU 5762 Teacher Bo

    题目链接:

      http://acm.hdu.edu.cn/showproblem.php?pid=5762

    题目大意

      给n个点,坐标范围0~m(n,m<=105),求是否存在2个点对满足哈夫曼距离相等。

    题目思路:

      【模拟】

      乍一看n2绝对T了,但是细想之下发现,坐标范围只有105,那么哈夫曼距离最多就2x105种,所以当循环超出这个范围时肯定能找到解(抽屉原理)。

     1 //
     2 //by coolxxx
     3 //
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<memory.h>
     9 #include<time.h>
    10 #include<stdio.h>
    11 #include<stdlib.h>
    12 #include<string.h>
    13 //#include<stdbool.h>
    14 #include<math.h>
    15 #define min(a,b) ((a)<(b)?(a):(b))
    16 #define max(a,b) ((a)>(b)?(a):(b))
    17 #define abs(a) ((a)>0?(a):(-(a)))
    18 #define lowbit(a) (a&(-a))
    19 #define sqr(a) ((a)*(a))
    20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    21 #define eps (1e-8)
    22 #define J 10000000
    23 #define MAX 0x7f7f7f7f
    24 #define PI 3.1415926535897
    25 #define N 100004
    26 using namespace std;
    27 typedef long long LL;
    28 int cas,cass;
    29 int n,m,lll,ans;
    30 struct xxx
    31 {
    32     int x,y;
    33 }a[N];
    34 bool u[N<<1];
    35 void work()
    36 {
    37     int i,j,x;
    38     for(i=1;i<=n;i++)
    39     {
    40         for(j=i+1;j<=n;j++)
    41         {
    42             x=abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y);
    43             if(u[x])
    44             {
    45                 puts("YES");
    46                 return;
    47             }
    48             u[x]=1;
    49         }
    50     }
    51     puts("NO");
    52 }
    53 int main()
    54 {
    55     #ifndef ONLINE_JUDGE
    56 //    freopen("1.txt","r",stdin);
    57 //    freopen("2.txt","w",stdout);
    58     #endif
    59     int i,j,x;
    60     for(scanf("%d",&cas);cas;cas--)
    61 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    62 //    while(~scanf("%s",s))
    63 //    while(~scanf("%d",&n))
    64     {
    65         memset(u,0,sizeof(u));
    66         scanf("%d%d",&n,&m);
    67         for(i=1;i<=n;i++)
    68             scanf("%d%d",&a[i].x,&a[i].y);
    69         work();
    70     }
    71     return 0;
    72 }
    73 /*
    74 //
    75 
    76 //
    77 */
    View Code
  • 相关阅读:
    Sentinel实现熔断和限流
    Nacos 服务注册和配置中心
    SpringCloud Sleuth 分布式请求链路跟踪
    SpringCloud Stream消息驱动
    SpringCloud Bus消息总线
    SpringCloud Config分布式配置中心
    Geteway服务网关
    Hystrix断路器
    libecc:一个可移植的椭圆曲线密码学库
    第四十二个知识点:看看你的C代码为蒙哥马利乘法,你能确定它可能在哪里泄漏侧信道路吗?
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5769049.html
Copyright © 2011-2022 走看看