Test instructions: To a convex hull, containing n points, to remove each point and then to find the convex hull, the average of points on the convex packet. Output in the simplest form of p/q, initially q=n. The topic requires that the convex hull is not allowed to have two adjacent edges parallel.
Link: http://codeforces.com/gym/100492 a question
Solution: I see no idea, may think of the enumeration to delete each point, its left point to the right point and then the convex hull method, although the complexity is still O (N), but it is extremely difficult to encode, and easy to write hang. Think more, found that only a few times convex hull can be, the positive solution is as follows. First, the convex hull is assumed, assuming that the convex hull has an even number of points 1. N, next, every two points indirectly shielding, first shielding the convex hull on the 1,3,5, ... n-1, then the convex hull, then the 1,3,5, ... when the n-1 point is deleted, calculate one of the answers, then block the 2,4,6, ... n points, and then calculate again, besides, You also calculate the deletion of points that are not on the convex hull. The sum of the three answers is the final answer. When the points on the convex hull are odd, an extra calculation is required, but the practice is similar. Pay attention to the calculation method of three or four times, do not count less or more.
Summary: This problem belongs to the method good to write, the method is difficult to write or even "can't write" the topic, the difficulty of thinking, coding easy, many write this type of problem to help improve thinking.
//hello. I ' m Peter.//#pragma comment (linker, "/stack:102400000,102400000")#include <cstdio>#include <iostream>#include <sstream>#include <cstring>#include <string>#include <cmath>#include <cstdlib>#include <algorithm>#include <functional>#include <cctype>#include <ctime>#include <stack>#include <queue>#include <vector>#include <set>#include <map>using namespace STD;typedef Long Longllinline intRead () {intx=0, f=1;CharCh=getchar (); while(ch>' 9 '|| ch<' 0 '){if(ch=='-') f=-1; Ch=getchar ();} while(ch>=' 0 '&&ch<=' 9 ') {x=x*Ten+ch-' 0 '; Ch=getchar ();}returnX*f;}Const DoubleEPS =1e-9, pi =ACOs(-1.0);inline intDCMP (Doublex) {if(fabs(x) < EPS)return 0;Else if(X >0)return 1;Else return-1;}structpoint{Doublex, y;intId Point () {}; Point (DoubleX1,Doubley1) {x = x1; y = y1; }};typedefPoint Vector; Vectoroperator- (ConstVector A,ConstVector b) {returnVector (a.x-b.x, a.y-b.y);}Double operator% (ConstVector A,ConstVector b) {returna.x * B.Y-A.Y * b.x;}BOOLCMP1 (ConstPoint A,ConstPoint B) {if(DCMP (a.x-b.x)! =0)returna.x < b.x;Else returnA.y < B.y;}#define N 200010intNotvis[n],kase;voidConvexhull (Point *p,intN, point *c,int&m) {m =0; for(inti =0; I < n; i++) {if(Notvis[p[i].id] = = Kase)Continue; while(M >1&& dcmp (c[m-1]-c[m-2])% (P[i]-c[m-1])) <=0) m--; c[m++] = P[i]; }intk = m; for(inti = n-2; I >=0; i--) {if(Notvis[p[i].id] = = Kase)Continue; while(M > K && dcmp (c[m-1]-c[m-2])% (P[i]-c[m-1])) <=0) m--; c[m++] = P[i]; }if(M >1) m--;} Point P[n], c[n], d[n];intN, M, nd;ll up, down;intMain () {Freopen ("Average.in","R", stdin); Freopen ("Average.out","W", stdout); n = read (); for(inti =0; I < n; i++) {intx, y; x = Read (), y = Read (); P[i] = point (x, y); P[i].id = i; Notvis[i] =0; } sort (p, p + N, CMP1); Kase =1; Convexhull (P, N, c, M); down = N; up =1LL * (n-m) * m;if(M &1) {Kase + +; for(inti =0; I < M-1; i + =2) {Notvis[c[i].id] = Kase; } convexhull (P, N, D, ND); up + = nd-((m>>1) +1) +1LL * (m>>1) * (M-1); Kase + +; for(inti =1; I < M-1; i + =2) {Notvis[c[i].id] = Kase; } convexhull (P, N, D, ND); up + = nd-((m>>1) +1) +1LL * (m>>1) * (M-1); kase++; notvis[c[m-1].id] = Kase; Convexhull (P, N, D, ND); up + = nd; }Else{Kase + +; for(inti =0; I < m; i + =2) {Notvis[c[i].id] = Kase; } convexhull (P, N, D, ND); up + = nd-(m>>1) +1LL * (m>>1) * (M-1); Kase + +; for(inti =1; I < m; i + =2) {Notvis[c[i].id] = Kase; } convexhull (P, N, D, ND); up + = nd-(m>>1) +1LL * (m>>1) * (M-1); } ll g = __GCD (up, down); Up/= G, down/= g;cout<<up<<"/"<<down<<endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Gym 100492A (convex packet, ingenious algorithm)