码迷,mamicode.com
首页 > 其他好文 > 详细

【模拟】HDU 5762 Teacher Bo

时间:2016-08-14 07:07:24      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:

  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

 

【模拟】HDU 5762 Teacher Bo

标签:

原文地址:http://www.cnblogs.com/Coolxxx/p/5769049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!