HDU 4968 Improving the GPA

Source: Internet
Author: User


Problem descriptionxueba: using the 4-point scale, my GPA is 4.0.

In fact, the average score of xueba is calculated by the following formula:
Average score = Σ (WI * scorei)/Σ (WI) 1 <= I <= N
Where scorei represents the scores of the ith course and WI represents the credit of the corresponding course.

To simplify the problem, we assume that the credit of each course is 1. in this way, the average score is Σ (scorei)/n. in addition, scorei are all integers between 60 and 100, and we guarantee that Σ (scorei) can be divided by N.

In sysu, the university usually uses the average score as the standard to represent the students 'level. however, when the students want to study further in foreign countries, other universities will use the 4-point scale to represent the students level. there are 2 ways of transforming each score to 4-point scale. here is one of them.


The student's average GPA in the 4-point scale is calculated as follows: GPA = Σ (gpai)/n
So given one student's average score and the number of the courses, there are still different possible values in the 4-point scale. please calculate the minimum and maximum value of the GPA in the 4-point scale.

Inputthe input begins with a line containing an integer T (1 <t <500), which denotes the number of test cases. the next t lines each contain two integers avgscore, n (60 <= avgscore <= 100, 1 <= n <= 10 ).
Outputfor each test case, You shoshould display the minimum and maximum value of the GPA in the 4-point scale in one line, accurate up to 4 decimal places. there is a space between two values.
Sample Input
 
475 175 275 375 10

Sample output
3.0000 3.20.2.7500 3.20.2.6667 3.16672.4000 3.2000HintIn the third case, there are always possible ways to calculate the minimum value of the GPA in the 4-point scale. for example, scores 78 74 73 GPA = (3.0 + 2.5 + 2.5)/3 = 2.6667 scores 79 78 68 GPA = (3.0 + 3.0 + 2.0) /3 = 2.6667 scores 84 74 67 GPA = (3.5 + 2.5 + 2.0)/3 = 2.6667 scores 100 64 61 GPa = (4.0 + 2.0 + 2.0)/3 = 2.6667

Question: Tell you the average number of N people, calculate the maximum and minimum average score.

Idea: simple DP, DP [I] [J] the maximum score of I total score J and

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 105; const double INF = 90000000.0; double DP [15] [1010], Tab [105]; double Lp [15] [1010]; int main () {for (INT I = 60; I <= 69; I ++) tab [I] = 2.0; For (INT I = 70; I <= 74; I ++) tab [I] = 2.5; for (INT I = 75; I <= 79; I ++) tab [I] = 3.0; For (INT I = 80; I <= 84; I ++) tab [I] = 3.5; For (INT I = 85; I <= 100; I ++) tab [I] = 4.0; memset (DP, 0, sizeof (DP); For (INT I = 60; I <= 100; I ++) DP [1] [I] = tab [I]; for (INT I = 2; I <= 10; I ++) for (Int J = 60; j <= 100; j ++) for (int K = J; k <= 1000; k ++) if (DP [I-1] [k-J]! = 0) DP [I] [k] = max (DP [I] [K], DP [I-1] [k-J] + TAB [J]); for (INT I = 0; I <= 10; I ++) for (Int J = 0; j <= 1000; j ++) lp [I] [J] = inf; For (INT I = 60; I <= 100; I ++) Lp [1] [I] = tab [I]; for (INT I = 2; I <= 10; I ++) for (Int J = 60; j <= 100; j ++) for (int K = J; k <= 1000; k ++) if (LP [I-1] [k-J]! = Inf) Lp [I] [k] = min (LP [I] [K], Lp [I-1] [k-J] + TAB [J]); int V, n; int t; scanf ("% d", & T); While (t --) {scanf ("% d", & V, & N ); printf ("%. 4lf %. 4lf \ n ", Lp [N] [N * V]/n, DP [N] [N * V]/n);} 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.