HDU5047Sawtooth (java large number), java large number

Source: Internet
Author: User

HDU5047Sawtooth (java large number), 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, so that we can find that ai = ai-1 + (I-1) limit 4 limit 4 + 1. after painting, we can find that each time a new side and the original side intersect, there will be 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 ();}}


Java big data problems

Public class BigInteger {
Private double son = 2.0;
Private double mother = 1.0;
Private int amount;
Private Double sum = 0.0;

Public BigInteger (int amount ){
This. amount = amount;
}

Public String getSum (){
For (int I = 0; I <amount; I ++ ){
Sum + = son/mother;
Son + = mother;
Mother = son-mother;
}
String result = sum. toString ();
Return result. substring (0, result. indexOf (".") + 7 );
}

Public static void main (String [] args ){
S = new partition (System. in );
BigInteger bi = new BigInteger (s. nextInt ());
System. out. println (bi. getSum ());
}
}

Use the JAVA big data class to implement the four arithmetic operations of large numbers

Public static void main (String [] args ){
// TODO Auto-generated method stub
BigInteger aa = new BigInteger ("100 ");
BigInteger bb = new BigInteger ("25 ");
BigInteger sub = aa. subtract (bb); // subtract a large integer
BigInteger add = aa. add (bb); // add a large integer
BigInteger mul = aa. multiply (bb); // multiplication of a large integer
BigInteger div = aa. divide (bb); // division of large Integers
System. out. println (sub. toString ());
System. out. println (add. toString ());
System. out. println (mul. toString ());
System. out. println (div. toString ());
}

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.