UVa 10213 (Euler formula +java large number) How many Pieces of land?

Source: Internet
Author: User

Test instructions

A circle of land, select n points in the circumference, and then 22 lines, asking how many pieces of this piece of land are divided?

Analysis:

First purple book on the formula is wrong, but according to the ideas provided in the book can be easily modified to get the correct answer!

Then push the formula, here to use the Euler formula of the plan, v-e + F = 2, where V is the number of vertices, E indicates the number of edges, and F represents the number of blocks of the polygon.

Minus the outermost infinite face, ask for ans = e-v + 1

Suppose N≥4, from a point on the circumference of the enumeration of a diagonal line, the left side of the I point, the right side of the n-2-i points, the left and the sides of the point 22 connected, on this diagonal to get an intersection. Each intersection is computed 4 times, plus the n points on the circumference, so

The next e is also very good calculation, a diagonal line has an intersection, so there is an edge, and here to note that each edge is repeated 2 times. Plus the n-point and N-points adjacent to the two-point line with n points separated by the circumference of N, so

And then based on these two formulas,

A little bit of simplification to get

Later found that the problem also requires high precision, so I foolishly wrote the high-precision addition and multiplication, and later found that the need for Division, Division is not written. Also think of LW seniors finishing Java BigInteger Some related things (Tools "java summary Version1.0), so never touch Java me, from the installation of Java JDK started, anger learning an afternoon Java, finally put this problem a. No, I'm so tired, but I'm glad.

1 ImportJava.io.*;2 ImportJava.util.*;3 Importjava.math.*;4 5  Public classMain6 {7     StaticPrintWriter out =NewPrintWriter (NewBufferedWriter (NewOutputStreamWriter (System.out));8     9      Public Static voidMain (String args[])throwsIOExceptionTen     { OneScanner cin=NewScanner (system.in); A         intKase =cin.nextint (); -          for(intc = 1; C <= Kase; ++c) -         { theBigInteger ans = biginteger.valueof (1); -String s =Cin.next (); -BigInteger n =NewBigInteger (s); -BigInteger temp =NewBigInteger (s); +             //System.out.println ("temp =" + temp); -temp = temp.multiply (Temp.subtract (NewBigInteger ("1"))); +             //System.out.println ("temp =" + temp); Atemp = Temp.divide (NewBigInteger ("2")); at             //System.out.println ("temp =" + temp); -Ans =Ans.add (temp); -temp = temp.multiply (N.subtract (NewBigInteger ("2"))); -temp = temp.multiply (N.subtract (NewBigInteger ("3"))); -temp = Temp.divide (NewBigInteger ("12")); -Ans =Ans.add (temp); in System.out.println (ans); -         } to     } +}
The slow Java King

UVa 10213 (Euler formula +java large number) How many Pieces's land?

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.