Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5299
Test instructions
There are n circles on the Euclidean plane, the circle will not intersect and will not be tangent, now Alice and Bob play the game, the two take turns to choose a circle to delete it and it contains all the circle (Alice Initiator), in their own round no circle can be deleted, ask you who will win the game
Solution: First, the relationship between the circle is abstracted, transformed into a tree, and then set the SG theorem (WoW, I don't know what is the SG theorem
To learn more, here is something related to the SG function: http://www.cnblogs.com/shjwudp/articles/4715439.html
And then there's the SG theorem (feeling like you don't want to shut it up!)
We have the following theorem: [theorem] The SG value of the leaf node is 0, and the SG value of the intermediate node is the XOR of the SG value of all its child nodes plus 1.
The problem of abstract circle is to look for, each circle directly contains the circle, read the Internet, basically is O (n^2), (there appears to be O (n logn)
Please read the code to understand it:
1 /*2 * Problem:3 * AUTHOR:SHJWUDP4 * Created TIME:2015/8/8 Saturday 15:06:485 * File name:1006.cpp6 * State:7 * Memo:8 */9#include <iostream>Ten#include <cstdio> One#include <vector> A#include <cstring> -#include <algorithm> - the using namespacestd; - - Const intdimension=2; - + structPoint { - Long LongX[dimension]; + }; A structCircle { at Point o; - intR; - }; - structEdge { - intu, v; -Edge (intUintv): U (U), V (v) {} in }; - to intN; +Vector<circle>arr; -Vector<edge>edges; thevector<vector<int> >G; * BOOLcmpConstCircle & A,ConstCircle &b) { $ returnA.r>B.R;Panax Notoginseng } - voidinit () { the edges.clear (); +G.assign (n+1, vector<int> (0)); A } the voidAddedge (intUintv) { + Edges.push_back (Edge (U, v)); -G[u].push_back (Edges.size ()-1); $ } $template<classT> T Sqr (t x) {returnX *x;} - BOOLJudgeintAintb) { - if(A==n | | b==n)return 1; the intD=0; - for(intk=0; k<dimension; k++) {WuyiD+=SQR (arr[a].o.x[k]-arr[b].o.x[k]); the } - intR=Max (ARR[A].R, ARR[B].R); Wu returnr*r>=D; - } About voidFinintUintx) { $ for(intI:g[u]) { -Edge & e=Edges[i]; - if(judge (x, e.v)) { - Fin (e.v, x); A return; + } the } - Addedge (U, x); $ } the intDfsintu) { the intres=0; the for(intI:g[u]) { theEdge & e=Edges[i]; -res^=1+DFS (E.V); in } the returnRes; the } About intMain () { the #ifndef Online_judge theFreopen ("inch","R", stdin); the //freopen ("Out", "w", stdout); + #endif - intT; thescanf"%d", &T);Bayi while(t--) { thescanf"%d", &n); the arr.resize (n); - for(intI=0; i<n; i++) { -Circle & c=Arr[i]; the for(intk=0; k<dimension; k++) { thescanf"%i64d", &c.o.x[k]); the } thescanf"%d", &C.R); - } the sort (Arr.begin (), Arr.end (), CMP); the the init ();94 for(intI=0; i<n; i++) fin (n, i); thePuts (DFS (n)?"Alice":"Bob"); the } the return 0;98}
hdu5299
[2015HDU Multi-School League supplementary title]hdu5299 Circles Game