Hdu1052 Tian Ji-the horse racing

Source: Internet
Author: User

Tian Ji's horse racing is a classic greedy, but it's hard to think of it. Every time you use the fastest and fastest, the slowest and the slowest to compare and judge

1) if Tian shortest is slower than Wang shortest, he will lose the game using the slowest comparison with Wang shortest. Otherwise, winning is of course the most cost-effective choice.

2) if Tian is slower than Wang, he will lose the game with the slowest comparison with Wang.

These two steps are greedy;

Also, pay attention to the situation ......

ViewCodeRight

#include 
  
    # include 
   
     int CMP (const void * a, const void * B) {return * (int *) A-* (int *) B;} int main () {int s [1001], t [1001], n; while (scanf ("% d", & n) = 1 & n! = 0) {for (INT I = 0; I 
    
      T [s2]) // compare the slowest horse, {sum1 ++; S1 ++; S2 ++;} else if (s [S1] 
     
       T [E2]) // compare the fastest horse {sum1 ++; E1 --; E2 --;} else if (s [E1] 
      
     
    
   
  

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.