Http://codeforces.com/gym/101055/problem/A
Title: Given some three-dimensional space points, you need to find a plane, can cover as many points as possible, only require output points. N<=50
Because of the small amount of data, we consider violence.
First, three points that are not in the same line, determine a plane, and then enumerate the other points. Judging, this complexity is n^4. can accept
Special Award. All points are in the same line. Direct Output N,
Later, after enumerating three points, we can calculate the normal vector of this plane, then enumerate the other points, and the quantity product of the normal vector is 0, we can ans++
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>Const intMAXN = -+ -;structcoor{intX, Y, Z//coordinates can also be expressed as vectors, and vectors are also a coordinate representation.coor () {} coor (intXxintYyintZZ): X (xx), Y (yy), Z (ZZ) {}BOOL operator& (Coor a)Const //determines whether two vectors are collinear, and the collinear returns True { //idea: Judging the cross product, whether the coefficients are 0 return(Y*A.Z-Z*A.Y) = =0&& (z*a.x-x*a.z) = =0&& (x*a.y-y*a.x) = =0; } cooroperator^ (coor a)Const //get the cross product of two vectors (that is, the vector product) and return a vector (coordinate) { returnCoor (y*a.z-z*a.y,z*a.x-x*a.z,x*a.y-y*a.x); } cooroperator-(Coor a)Const //if it's c-d, get the vector DC, { returnCoor (x-a.x,y-a.y,z-a.z); } int operator* (Coor a)Const //get the number of two vectors and return an integer { returnx*a.x+y*a.y+z*a.z; }}A[MAXN];BOOLAll_in_aline (intN) { //ideas, violent enumeration, every three points, see if all the cross product are 0 for(intI=1; i<=n;++i)//Take this as a starting point. for(intj=i+1; j<=n;++j) for(intk=j+1; k<=n;++k) {coor t1= a[k]-A[i]; Coor T2= a[j]-A[i]; if(T1&T2)Continue; return false; } return true;}BOOLcheckthree (coor a,coor b,coor c) {return(b-a) & (C-a);}voidWork () {intN; CIN>>N; for(intI=1; i<=n;++i) cin>>a[i].x>>a[i].y>>a[i].z; if(All_in_aline (n))//If you are in the same line, you can directly judge{cout<<n<<Endl; return ; } intans=3; for(intI=1; i<=n;++i) for(intj=i+1; j<=n;++j) for(intk=j+1; k<=n;++k) {if(Checkthree (A[i],a[j],a[k]))Continue; intt=3; Coor t1= (A[k]-a[i]) ^ (a[j]-a[i]);//Vertical Vector for(intH=1; h<=n;++h) {if(h==i| | h==j| | H==K)Continue; if((A[h]-a[i]) *t1 = =0) t++; } ans=Max (ans,t); } cout<<ans<<Endl; return ;}intMain () {#ifdef local freopen ("Data.txt","R", stdin);#endifWork (); return 0;}
View Code
Gym 101055A Computational Geometry, violence