2014 + schools 1009 -- hdu4968 -- Improving the GPA (maximum and minimum average credits for average scores)

Source: Internet
Author: User
Improving the GPA

Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/131072 K (Java/Others)
Total submission (s): 65 accepted submission (s): 43

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.00002.7500 3.00002.6667 3.16672.4000 3.2000HintIn the third case, there are many 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.6667Scores 79 78 68 GPA = (3.0 + 3.0 + 2.0) / 3 = 2.6667Scores 84 74 67 GPA = (3.5 + 2.5 + 2.0) / 3 = 2.6667Scores 100 64 61 GPA = (4.0 + 2.0 + 2.0) / 3 = 2.6667 

Given the average score of N subjects, how much is the lowest and highest average credits?

A very troublesome question at the beginning, because the score is not certain, the score is divided into five score segments, each segment can have the ki section, each score segment of the subjects is n, in this way, all the possibilities are traversed. If each segment has the highest score, an average score of the highest possible is obtained. The lowest score is obtained for each segment, if the average score is given within this period, the score may exist. Calculate the average credits of the case and obtain the minimum and maximum average credits of all cases.

Time: N is a maximum of 10. Therefore, you need to determine a maximum of four segments to obtain the number of subjects in the last segment. The time is 10 ^ 4.


#include <cstring>#include <cstdio>#include <math.h>#include <algorithm>using namespace std;int main(){    int t, n, a, i, tot, j, k, h, i1, j1, k1, h1, i2, j2, k2, h2;    double max1, tmp, min1;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&a,&n);        max1=-1;        min1=1e9;        a*=n;        for(i=0; i<=n; i++)        {            i1=i*100;            i2=i*85;            for(j=0; j<=n-i; j++)            {                j1=j*84;                j2=j*80;                for(k=0; k<=n-i-j; k++)                {                    k1=k*79;                    k2=k*75;                    for(h=0; h<=n-i-j-k; h++)                    {                        h1 = h * 74 ;                        h2 = h * 70 ;                        int z=n-i-j-k-h;                        ////printf("zz --- %d %d %d %d %d\n" , i, j, k, h, z);                        int maxans=i1+j1+k1+h1+z*69;                        int minans=i2+j2+k2+h2+z*60;                        if(a>=minans&&a<=maxans)                        {                             //printf("kkkk --- %d %d %d %d %d\n" , i, j, k, h, z);                            tmp=i*4+j*3.5+k*3.0+h*2.5+z*2;                            if(max1<tmp)                            {                                max1=tmp;                                //printf("max --- %d %d %d %d %d\n" , i, j, k, h, z);                            }                            if(min1>tmp)                            {                                min1=tmp;                                //printf("min --- %d %d %d %d %d\n" , i, j, k, h, z);                            }                        }                    }                }            }        }        printf("%.4lf %.4lf\n",min1/n,max1/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.