HDU5047Sawtooth (java large number)

Source: Internet
Author: User

HDU5047Sawtooth (java large number)

HDU5047Sawtooth (java large number)

Question Link

Draw n "M" in a rectangle and ask how to divide the rectangle into the largest area. The number of regions.

Solution: the best way to solve the problem is that each newly painted "M" line is connected with the existing line. In this way, we can find that ai = ai-1 + (I-1 )? 4? 4 + 1. After painting, we can find that each new side and the original side will have four more areas. There will also be a small-angle area. Last formula: ai = a0 + 8 I-7 * I; a0 = 1; use a large number, and the input and output of the large number must be faster (with buffered ), otherwise, it will be TLE.

Code:

Import java. util. *; import java. io. *; import java. math. *; public class Main {public static void main (String args []) {using cin = new using (new BufferedInputStream (System. in); PrintWriter cout = new PrintWriter (new BufferedOutputStream (System. out); // The reading speed is faster than int T; T = cin. nextInt (); BigInteger n; for (int I = 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 ();}}

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.