NYOJ 914 maximize Yougth

Source: Internet
Author: User

Yougth maximum time limit: 1000 MS | memory limit: 65535 KB difficulty: 4

Description

The weight and value of n items in Yougth are Wi and Vi. Can you help him select k items to maximize the value of unit weight?

Input
Multiple groups of test data
The first row of each group of test data has two numbers n and k, and the next row has n numbers Wi and Vi.
(1 <= k = n <= 10000) (1 <= Wi, Vi <= 1000000)
Output
Outputs the maximum unit value. (Retain two decimal places)
Sample Input
3 22 25 32 1
Sample output
0.75
Idea: Binary and greedy
#include
       
        #include
        
         #includeusing namespace std;int w[10000],v[10000],n,k;double y[10000];bool C(double x){ for(int i=0;i
         
          =0;}void solve(){            double lb =0,ub=10000;            for(int i=0;i<100;i++)            {               double mid =(lb+ub)/2;               if(C(mid)) lb = mid;               else ub=mid;            }            printf("%.2f\n",ub);}int main(){      while(cin>>n>>k)    {   for(int i=0;i
          
           >w[i]>>v[i];   solve();   //system("pause");    }   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.