Test instructions: A circle of land, select n points in the circumference, and then 22 lines, ask how many pieces of this piece of land into?
Analysis: This problem uses Euler formula, in the plan, v-e+f=2, where V is the number of vertices, E is the number of edges, F is the number of polygons. For this problem, just calculate V and e as well.
We enumerate the diagonal from a vertex, the line to the left of the I point, then the right side of the n-i-2 point, then the two sides of the lines on this diagonal form I * (n-i-2) intersection, get I * (n-i-2) + 1 line segments, but each intersection,
Repeated calculations four times, each line is repeated calculated two times, so the total is, V plus n means to add the original n vertices, E plus 2n means,
First add the original n points adjacent to the number of edges, and then add the ellipse by the circle is divided into the N-side, and finally the total number of polygons minus the "infinite face." This formula does not use the cycle to calculate, to simplify the formula, the final result is quite simple.
Ans = n * (n-1) * (n-2) * (n-3)/24 + n * (n-3)/2 + n + 1.
The code is as follows:
Import Java.math.biginteger;import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner c in = new Scanner (system.in); int T; T = Cin.nextint (); for (int i = 0; i < T; ++i) {BigInteger n = cin.nextbiginteger (); BigInteger n1 = n.subtract (Biginteger.one); BigInteger N2 = N1.subtract (Biginteger.one); BigInteger n3 = N2.subtract (Biginteger.one); BigInteger a = n.multiply (n1). Multiply (N2). Multiply (N3). Divide (Biginteger.valueof (24)); BigInteger B = n.multiply (n3). Divide (biginteger.valueof (2)); BigInteger ans = a.add (b). Add (N). Add (Biginteger.one); System.out.println (ANS);}}
UVa 10213 How many Pieces of land? (Calculate geometry + large number)