UVa 10213 How many Pieces of land? (Calculate geometry + large number)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.