Topic Link: UVA 11123-counting trapizoid
Topic: Given a number of points, ask how many kinds of trapezoid, not including the rectangle, trapezoidal area must be positive. Because it is a collection of points, it does not have the advantage of repeating points.
Problem-Solving ideas: Enumerate 22 points, find out the line, including the slope k, the offset value C, and the length L. The nature of the trapezoid is known, a pair of pairs of sides parallel, that is, a pair of parallel but unequal edges.
So all the segments are sorted by slope, assuming that for a certain slope, there are m-bars, then the M-bar can be composed of a quadrilateral with parallel pairs of edgesC (2yrd), requires the trapezoid also to reduce the length of the same and collinear, respectively, the same is the same as the same as C, but according to the principle of the repulsion, to be added back to both L and C are equal parts.
#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <algorithm>using namespace STD;Const intN =205;Const DoubleEPS =1e-9;Const DoublePI =4*Atan(1.0);structLine {DoubleK, C, l; Line (DoubleKDoublec =0,DoubleL =0) { This->k = k; This->c = C; This->l = l; }friend BOOL operator< (Constline& A,Constline& b) {returnA.K < B.K; }};structState {DoubleC, L; State (DoubleCDoubleL) { This->c = C; This->l = l; }};intNDoubleX[n], y[n]; vector<line> Set; vector<state>Ginline DoubleDistant (DoubleXiDoubleYi) {returnXi * xi + yi * yi;}inline DoubleCal (intAintb) {if(X[a] = = X[b])returnX[a];returnY[a]-X[a] * ((Y[a]-y[b])/(X[a]-x[b]));}inline intCintA) {if(A <1)return 0;returnA * (A-1) /2;}inline BOOLCmpC (Conststate& A,Conststate& b) {if(fabs(A.C-B.C) > EPS)returnA.C < B.C;returnA.l < B.L;}inline BOOLCmpl (Conststate& A,Conststate& b) {returnA.l < B.L;}intJudge () {sort (G.begin (), G.end (), CmpC);intAns =0, cnt =1, TMP =1;/ * for (int i = 0; i < g.size (); i++) {printf ("%lf%lf\n", g[i].c, G[I].L); } printf ("\ n"); */ for(inti =1; I < g.size (); i++) {if(fabs(g[i].c-g[i-1].C) > EPs) {ans = ans + c (CNT)-C (TMP); CNT =0; TMP =0; }if(fabs(g[i].l-g[i-1].L) > EPs) {ans = ans-c (TMP); TMP =0; } tmp++; cnt++; } ans = ans + c (CNT)-C (TMP); Sort (G.begin (), G.end (), Cmpl); CNT =1; for(inti =1; I < g.size (); i++) {if(fabs(g[i].l-g[i-1].L) > EPs) {ans = ans + C (CNT); CNT =0; } cnt++; } ans = ans + C (CNT);returnAns;}intSolve () {intAns =0;if(Set. Size () = =0)return 0; G.clear (); G.push_back (State (Set[0].C,Set[0].L)); for(inti =1; I <Set. Size (); i++) {//printf ("%d%LF!!!!!!! \ n ", I, SET[I].K); if(fabs(Set[I].K-Set[I1].K) > EPs) {ans + = C (G.size ())-judge (); G.clear (); } G.push_back (State (Set[I].c,Set[I].L)]; } ans + = C (G.size ())-judge ();returnAns;}intMain () {intCAS =1; while(scanf("%d", &n) = =1&& N) {Set. Clear (); for(inti =0; I < n; i++) {scanf("%LF%LF", &x[i], &y[i]); for(intj =0; J < I; J + +)Set. Push_back (Line (atan2(Y[j]-y[i], x[j]-x[i]), Cal (I, J), Distant (Y[i]-y[j], x[i]-x[j])); } for(inti =0; I <Set. Size (); i++) {if(Set[I].K < EPS]Set[I].k + = PI; } sort (Set. Begin (),Set. end ());/* for (int i = 0; i < set.size (); i++) {printf ("%d%lf%lf%lf\n", I, SET[I].K, SET[I].C, Set[i ].L); } */ printf("Case%d:%d\n", cas++, Solve ()); }return 0;}