is to give a lot of points, the requirements are divided into two sets, in the same set of points require any two of the distance between more than 5.
Ask for a collection, and its number of points is the least of all possible answers.
Explode the search directly from any point and throw it in a different set of points. Just keep doing it.
Because there may be a lot of miles away, add up the smallest number of each search you get.
Because all points are on the grid, it is only necessary to enumerate whether the points that a point can contain exist in the data.
Of course, you can also use a tree directly to find, which I do not.
The complexity of time is 81nlogn
Lake big OJ machine too old ... Also to open the stack ... UVA live casually hand over.
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;struct point{int x, y; Point () {}, point (int x,int y) {this->x=x; this->y=y; } bool operator < (point one) const {if (x!=one.x) return x<one.x; Return y<one.y; }};vector<point>bx;int Dis2 (Point one,point) {return (one.x-two.x) * (one.x-two.x) + (ONE.Y-TWO.Y) * (one.y-two . y);} void Create () {for (Int. i=-5;i<=5;i++) for (int j=-5;j<=5;j++) if (Dis2 (i,j), Poi NT (0,0)) <=25) Bx.push_back (Point (I,j));} map<point,int>mp; Point Cnt;void dfs (Point v) {int n=bx.size (), no=mp[v]; Map<point,int>::iterator it; for (int. i=0;i<n;i++) {point t=point (V.X+BX[I].X,V.Y+BX[I].Y); It=mp.find (t), if (It!=mp.end () &&it->second==0) {if (no==1) { it->second=2; cnt.y++; } else {it->second=1; cnt.x++; } dfs (t); }}}int Main () {//int size = << 256MB//char *p = (char*) malloc (size) + size; __asm__ ("Movl%0,%%esp\n":: "R" (p)); Create (); int n; while (scanf ("%d", &n)!=eof) {while (n--) {point T; scanf ("%d%d", &T.X,&T.Y); mp[t]=0; } Map<point,int>::iterator it; int ans=0; For (It=mp.begin (); It!=mp.end (); it++) { if (it->second==0) {it->second=1; Cnt.x=1; cnt.y=0; DFS (It->first); if (CNT.X>CNT.Y) swap (CNT.X,CNT.Y); Ans+=cnt.x; }} cout<<ans<<endl; } return 0;}
Time limit: 15000ms, special time limit:37500ms, Memory Limit:65536KB |
Total Submit Users: 9, Accepted users: 6 |
problem 13307: No Special Judgement |
Problem description |
The Andromeda Galaxy is expected-collide with our Milky-in-the-about 3.8 billion years. The collision would probably be a merging of the the galaxies, with no and the stars actually colliding. That's because the distance between stars in both galaxies are so huge. Professor Andrew is building a computational model to predict the possible outcomes of the collision and needs your help! A set of points in the dimensional plane are given, representing stars in a certain region of the already merged Galaxi Es. He does not know which stars came originally from which Galaxy; But he knows that, for this region, if both stars came from the same galaxy, then the distance between them are greater than 5 light years. Since every star in the "comes either from Andromeda" or "from the Milky", the professor also knows that the given Set of points can separated into disjoint subsets, one comprising stars from Andromeda and the other one stars fro M the Milky, both subsets with the propErty that the minimum distance between and the points in the subset are greater than 5 light years. He calls this a good separation and the bad news was that there could be many different good separations. However, among all possible good separations there are a minimum number of stars a subset must contain, and this is the NUM BER your program have to compute.
|
Input |
The first line contains a integer N (1≤n≤5x10^4) representing the number of points in the set. Each of the next N lines describes a different point with both integers X and Y (1≤X,Y≤5X10^5), indicating its coordi Nates, in light years. There is no coincident points, and the set admits at least one good separation.
|
Output |
Output a line with an integer representing the minimum number of points a subset may has in a good separation.
|
Sample Input |
Sample Input 161 111 713 4Sample Input 2210 1050 30 |
Sample Output |
Sample Output 12Sample Output 20 |
Problem Source |
ICPC Latin American Regional? 2014 |
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA live 6827 Galaxy collision