UVA1523-Helicopter (brute force + full ranking)

Source: Internet
Author: User

Question Link


Question:Eight passengers sat on a helicopter and asked for the minimum m value of the center of gravity.

Ideas:According to the formula given by the question, we can know that to minimize M, that is, to minimize the sum of MV and MH, we can use a full arrangement, place each value on each seat, and then update the minimum value.

 # include 
   
     # include 
    
      # include 
     
       # include 
      
        # include 
       
         using namespace STD; const int INF = 0x3f3f3f; int A [8]; int main () {While (1) {for (INT I = 0; I <8; I ++) scanf ("% d", & A [I]); If (! A [0] &! A [1] &! A [2] &! A [3] &! A [4] &! A [5] &! A [6] &! A [7]) break; sort (A, A + 8); double min = inf; do {double mV, MH, M; double x1, x2, Y1, Y2; x1 = A [5] + A [6] + A [7]; x2 = A [0] + A [1] + A [2]; y1 = A [2] + A [4] + A [7]; y2 = A [0] + A [3] + A [5]; MV = POW (x1-X2), 2); MH = POW (Y1-Y2), 2); M = SQRT (MV + Mh ); if (min> m) min = m;} while (next_permutation (A, A + 8); printf ("%. 3lf \ n ", min) ;}return 0 ;}
       
      
     
    
   




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.