POJ 2590 Steps (ZOJ 1871)

Source: Internet
Author: User

 

Question:

For two dots a and B, it is required to move from a to B. The number of each moving step is greater than or equal to or less than 1 in the previous step. Calculate the minimum number of steps. (The start and end steps must be 1)

 

Ideas:

Directly symmetric.

For example:

1-> 7

Can be 1 2 2 1

1-> 9

1 2 3 2 1

50

1 2 3 4 5 6 7 6 5 4 3 2 1

 

The two OJ input formats are different ..

Below is the POJ's:

 

# Include

 
  
Int main () {int T; scanf (% d, & T); while (T --) {int a, B; scanf (% d, &, & B); if (a = B) {printf (0); continue;} int target = B-a; int sum = 0; int step = 1; int ans = 0; while (sum * 2 + 2 * step

  
   
ZOJ:

   

 

 

# Include

    
     
Int main () {int a, B; while (~ Scanf (% d, & a, & B) {if (a = B) {printf (0); continue;} int target = B-; int sum = 0; int step = 1; int ans = 0; while (sum * 2 + 2 * step

     

      

 

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.