Ytu 1002:home Work (greedy)

Source: Internet
Author: User

1002:home work time limit: Sec Memory Limit:
Submit: 204 Solved: 29
[Submit] [Status] [Web Board] Description

Near the beginning of school, everyone is busy packing their bags ready to go back, but i_love_c not worry about it! Because his mind is all in the summer homework: so far not activated (-_-!! I thought he was a little calmer.
Summer homework is a lot of papers, we have climbed out of the test paper, the people know that the question on the papers have a choice of questions, fill in the blanks, simple answer questions, such as proof. The advantage of making a choice problem is that the workload is very small, but also because the problem of choice is generally very long. If there are 5 papers, 4 of which are choice questions, and the last one is the blanks, it is obvious that the last one will take longer than the first 4. But if you only do the choice, although the workload is very small, but on the surface seems to have done 4/5 of the homework. I_love_c decided to muddle through in such a way.
He counted the time it took to finish each test paper and the value it would get when it was done (according to the above principle, the more the choice of the question, the higher the value of course). Now ask you to arrange for him to do the most valuable homework with only a little time left for him.

Input

The test data includes multiple groups. Each set of test data starts with two integers m,n (0≤m≤20, 1≤n≤10000), each representing the number of papers and the time remaining for I_love_c. Next there are m lines, each of which consists of two integers t,v (1≤t≤n,0<v<10000), each representing the time required to complete the test paper and the value that can be gained after it is done! The input ends with 0 0.

Output

Corresponds to the maximum value that can be obtained for each set of test data output i_love_c.
Keep the decimal point 2 bits

Sample Input
4 204 105 2210 31 20 0
Sample Output
37.00
HINT

The accuracy of float may not be sufficient. You should use the double type. Report See http://acm.zjgsu.edu.cn/Report/1001/1001.html

Source

Freeproblemset

AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace    Std;struct work{double time,v; Double JZ;}; BOOL Comp (work A,work b) {return A.JZ&GT;B.JZ;}    int main () {int m,n;    Work my[11111];    int i,j;    Double k; while (cin>>n>>m&& (n| |            m) {for (i=0;i<n;i++) {cin>>my[i].time>>my[i].v;        My[i].jz=my[i].v/my[i].time; }//For (i=0;i<n;i++) cout<<my[i].time<< ' <<my[i].v<< ' <<my[i].jz<< ' \12 ';        cout<< ' \12 ';        Sort (my,my+n,comp); for (i=0;i<n;i++) cout<<my[i].time<< ' <<my[i].v<< ' <<my[i].jz<< ' \12 ';        cout<< ' \12 ';        j=0,k=0;                for (i=0;i<n;i++) {if (j+my[i].time<=m) {j+=my[i].time;            K+=MY[I].V;                    } else{if (j!=m) {j=m-j; k+=j*my[I].JZ;            } break;    }} printf ("%.2lf\n", K); } return 0;}


Ytu 1002:home Work (greedy)

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.