java--Algorithm Special training (1) brute force and practicality first

Source: Internet
Author: User

The main contents of the first lesson:
Brute force and practicality first (1) The importance of brute force in competition and enterprise Application (2) Practical principles in Brute force ( 3) Inverse solution (4) enumeration method

Topic One:
American mathematician Wiener (N.wiener) had a precocious intellect and went to college at the age of 11.
He was invited to lecture at Tsinghua University in China for 1935-1936 years. Once, he attended an important meeting, and the young faces were striking. Then someone asked him about his age, and he replied, "My age Cube is a 4-digit number." My 4-time-old is a 6-digit number. These 10 numbers just happen to contain 10 numbers from 0 to 9, each of which happens 1 times at a time. "Please calculate how young he was at that time."

Problem Solving methods:
1  PackageCom.algorithm.java.blueBirdge;2 3 //import static sun.misc.Version.println;4 5  Public classTESTSUANFA {6      Public Static voidMain (string[] args) {7         //assuming his age is between 1 and 100 years (40)8          for(inti=10;i<100;i++){9             //four-time judgment on the age of the cubic and the ageTen             intA =i*i*i; One             intb=a*i; A             //turn A into a string -             if(A + ""). Length ()!=4)Continue;//If you convert a from a number to a string, the length is not 4, jump out of the loop -             if(b + ""). Length ()!=6)Continue;//If the B is converted from a number to a string, the length is not 6, jumping out of the loop theSYSTEM.OUT.PRINTLN (i + "four times is" +a+ "of the six-time side is" +b); -         } -     } -  +}

Test results:

Results can be seen: 18

Write the program requirements: practical, fast, stable, effective!



java--Algorithm Special training (1) brute force and practicality first

Related Article

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.