Hdu5047sawtooth (Java large number)

Source: Internet
Author: User

Hdu5047sawtooth (Java large number)

Topic links

The main idea: in a rectangular drawing of n "M", asked how to draw the rectangle can be divided into the most areas. Give the number of this area.

Solution thinking: The best way is that each new picture of the "M" line and the original line intersect, so you can find AI = ai-1 + (i-1)? 4? 4 + 1. You can see that each new edge and the original edge intersect each other 4 more areas. Finally, there will be a small corner area to come out more. Last formula: Ai = a0 + 8Ii-7 * i;a0 = 1, to use large numbers, and the large number of input and output to use faster (with buffered), otherwise it will tle.

Code:

Import Java.util.*;import Java.io.*;import java.math.*; Public classMain { Public Static voidMain (String args[]) {ScannerCin=NewScanner (NewBufferedinputstream (system.in)); PrintWritercout=NewPrintWriter (NewBufferedoutputstream (System.out));//Read in the output speed is relatively fast        intT T =Cin. Nextint (); BigInteger N; for(inti =1; I <= T; i++) {n =Cin. Nextbiginteger (); BigInteger A = biginteger.valueof (1); BigInteger ans = biginteger.valueof (8). Multiply (n). Multiply (n). Subtract (Biginteger.valueof (7). Multiply (n)). Add (a);cout.printf("Case #%d:", i);cout. println (ANS); }Cin. Close ();cout. Close (); }}

Hdu5047sawtooth (Java 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.