Swust OJ Gold Nuggets distribution (0490)

Source: Internet
Author: User

Gold Nuggets distribution (0490)

Time limit (ms): Memory Limit (KB): 65535 submission:421 accepted:234 descriptionbosses has a bag of gold. Each month there would be the employees to their outstanding performance were a Gold award. In line with the rituals, ranking first employees would receive the heaviest nugget, ranked second employee would be the Lig Htest Gold. Under this method, unless the nuggets to a new bag, otherwise employees received the first gold always be employees than t He second-nuggets. If There is a new cyclical nuggets joined bag, every month to find the lightest and most of the nuggets. Assuming that there are a comparison of weight machines, we hope thatAt least by comparisonTo identify the number and the lightest weight of gold. (The title description is not translated, in short, the meaning is to find the largest element and the smallest element in the array, there is a requirement that the least number of comparisons) Inputtwo lines
The first line was a number of gold nuggets and less than 50000
The second line is weight of every gold nugget. Outputtwo numbers
The first is weight of the heaviest nugget
The second is weight of the lightest gold sample Input65 2 7 6 3 4 Sample Output7 2 Hintsourcemryang
1#include <iostream>2 using namespacestd;3 4 inta[2000000];5 6 intMain ()7 {8     intn,i,j,max=0, min=99999;9Cin>>N;Ten      for(i=0; i<n;i++) OneCin>>A[i]; A      for(i=0, j=n-1; i<=j;i++,j--) -     { -         if(a[i]<A[j]) the         { -             if(a[i]<min) -min=A[i]; -             if(a[j]>max) +max=A[j]; -         } +         Else A         { at             if(a[j]<min) -min=A[j]; -             if(a[i]>max) -max=A[i]; -         } -     } incout<<max<<' '<<min<<Endl; -     return 0; to}

Note: Two number comparison, then that large number, it is impossible to be the smallest number in this group, the same, the small number, it is impossible to become the largest number of the group. From the usual 2*n comparison, it becomes the (N/2) *3=1.5*n comparison.

Swust OJ Gold Nuggets distribution (0490)

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.