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 ();}}