Test instructions: There are many points, starting from the bottom right corner of the point, the initial direction level to the right, and then each step can only go to the left, ask the maximum number of points to walk.
Solution: Greedy to engage in the words, it is sure to choose the left side of the lowest angle with the point, and then walk over. Then it is the equivalent of a simulated to go to the point, then count, and then walk over. That's how it's done.
I use set and vector here.
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<vector>#include<Set>#defineMod 1000000007#definePi ACOs (-1.0)#defineEPS 1e-8using namespacestd;intnonsense;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {}voidInput () {scanf ("%D%LF%LF",&nonsense,&x,&y); }};typedef point Vector;intDCMP (Doublex) {if(x <-eps)return-1; if(X > EPS)return 1; return 0;} Template<classT> T Sqr (t x) {returnX *x;} Vectoroperator+ (vector A, vector B) {returnVector (a.x + b.x, A.Y +b.y); }vectoroperator-(vector A, vector B) {returnVector (a.x-b.x, A.Y-b.y); }vectoroperator* (Vector A,DoubleP) {returnVector (A.x*p, a.y*p); }vectoroperator/(Vector A,DoubleP) {returnVector (a.x/p, a.y/p); }BOOL operator< (Constpoint& A,Constpoint& b) {returnA.y < B.Y | | (A.y = = B.y && a.x <b.x); }BOOL operator>= (Constpoint& A,Constpoint& b) {returna.x >= b.x && a.y >=b.y;}BOOL operator<= (Constpoint& A,Constpoint& b) {returna.x <= b.x && a.y <=b.y;}BOOL operator== (Constpoint& A,Constpoint& b) {returnDCMP (a.x-b.x) = =0&& dcmp (a.y-b.y) = =0; }DoubleDot (vector A, vector B) {returna.x*b.x + a.y*b.y;}DoubleLength (Vector A) {returnsqrt (Dot (A, a));}DoubleAngle (vector A, vector B) {returnACOs (Dot (A, B)/Length (a)/Length (B)); }DoubleCross (vector A, vector B) {returna.x*b.y-a.y*b.x;}//Data SegmentPoint p[ -];Set<int>Sk;vector<int>ans;//Data EndsintMain () {intt,n,i,j; scanf ("%d",&t); while(t--) {scanf ("%d",&N); Sk.clear (), ans.clear (); for(i=1; i<=n;i++) P[i].input (), Sk.insert (i); intMintag =1; DoubleMiny = p[1].Y, Minx = p[1].x; for(i=2; i<=n;i++) { if(P[i].y <miny) Mintag= i, miny = p[i].y, Minx =p[i].x; Else if(P[i].y = = Miny && p[i].x <Minx) Mintag= i, Minx =p[i].x; } Vector Now= Vector (1,0); Point Pnow=P[mintag]; Ans.push_back (Mintag); Sk.erase (Mintag); Set<int>:: Iterator it; while(1) { DoubleMini =Mod; inttag; for(It=sk.begin (); It!=sk.end (); it++) {Point A= p[*it]-Pnow; DoubleAng =Angle (now,a); if(Ang <Mini) Mini= ang, Tag = *it; } if(Mini >= Mod) Break; now= p[tag]-Pnow; Pnow=P[tag]; Ans.push_back (tag); Sk.erase (tag); if(Sk.empty ()) Break; } printf ("%d", Ans.size ()); for(i=0; I<ans.size (); i++) printf ("%d", Ans[i]); Puts (""); } return 0;}
View Code
POJ 1696 Space Ant--enumeration, simulation, greed, geometry