Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=5762
Main Topic :
Give n points, coordinate range 0~m (n,m<=105), to find whether there are 2 points to meet Huffman distance equal.
Topic Ideas:
Simulation
At first glance N2 Absolute T, but under the small thought found that the coordinate range is only 105, then Huffman distance is the most 2x105 species, so when the cycle beyond this range will certainly find the solution (drawer principle).
1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> - //#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineLowbit (a) (a& (a)) + #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) + #defineEPS (1E-8) A #defineJ 10000000 at #defineMAX 0x7f7f7f7f - #definePI 3.1415926535897 - #defineN 100004 - using namespacestd; -typedefLong LongLL; - intCas,cass; in intN,m,lll,ans; - structXXX to { + intx, y; - }a[n]; the BOOLu[n<<1]; * voidWork () $ {Panax Notoginseng inti,j,x; - for(i=1; i<=n;i++) the { + for(j=i+1; j<=n;j++) A { theX=abs (a[i].x-a[j].x) +abs (a[i].y-a[j].y); + if(U[x]) - { $Puts"YES"); $ return; - } -u[x]=1; the } - }WuyiPuts"NO"); the } - intMain () Wu { - #ifndef Online_judge About //freopen ("1.txt", "R", stdin); $ //freopen ("2.txt", "w", stdout); - #endif - inti,j,x; - for(SCANF ("%d", &cas); cas;cas--) A //for (scanf ("%d", &cas), cass=1;cass<=cas;cass++) + //while (~scanf ("%s", s)) the //while (~scanf ("%d", &n)) - { $memset (U,0,sizeof(U)); thescanf"%d%d",&n,&m); the for(i=1; i<=n;i++) thescanf"%d%d",&a[i].x,&a[i].y); the Work (); - } in return 0; the } the /* About // the the // the */
View Code
"Analog" HDU 5762 Teacher Bo