1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <vector>
5 #include <map>
6 using namespace std;
7 const int inf = 0x3f3f3f3f;
8 const int MAX = 200+10;
9 double GPA[10],dp1[20][30000],dp2[20][30000];
10 map<int,int> hash;
11 void init() {
12 memset(GPA,0,sizeof(GPA));
13 for(int i=60;i<=69;i++) hash[i]=1;
14 for(int i=70;i<=74;i++) hash[i]=2;
15 for(int i=75;i<=79;i++) hash[i]=3;
16 for(int i=80;i<=84;i++) hash[i]=4;
17 for(int i=85;i<=100;i++) hash[i]=5;
18 GPA[1]=2.0; GPA[2]=2.5; GPA[3]=3.0;
19 GPA[4]=3.5; GPA[5]=4.0;
20 memset(dp2,0,sizeof(dp2));
21 for(int i=0;i<=10;i++) {
22 for(int j=0;j<=1000;j++) dp1[i][j]=inf;
23 }
24 for(int i=60;i<=100;i++) {
25 dp1[1][i]=GPA[hash[i]];
26 dp2[1][i]=GPA[hash[i]];
27 }
28 for(int i=2;i<=10;i++) {
29 for(int v=0;v<=1000;v++) {
30 for(int j=60;j<=100;j++) {
31 if(v>=j) {
32 if(i==1) {
33 dp1[i][v]=min(dp1[i][v],dp1[i-1][v-j]+GPA[hash[j]]);
34 dp2[i][v]=max(dp2[i][v],dp2[i-1][v-j]+GPA[hash[j]]);
35 }
36 else if(((double)(v-j)/(double)(i-1))>=60) {
37 dp1[i][v]=min(dp1[i][v],dp1[i-1][v-j]+GPA[hash[j]]);
38 dp2[i][v]=max(dp2[i][v],dp2[i-1][v-j]+GPA[hash[j]]);
39 }
40 }
41 }
42 }
43 }
44
45
46 }
47 int main() {
48 int n,cnt,ave; init();
49 scanf("%d",&n);
50 while(n--) {
51 scanf("%d %d",&ave,&cnt);
52 int tot=ave*cnt;
53 printf("%.4lf %.4lf ",dp1[cnt][tot]/(double)cnt,dp2[cnt][tot]/(double)cnt);
54 }
55 return 0;
56 }
2 #include <cstring>
3 #include <algorithm>
4 #include <vector>
5 #include <map>
6 using namespace std;
7 const int inf = 0x3f3f3f3f;
8 const int MAX = 200+10;
9 double GPA[10],dp1[20][30000],dp2[20][30000];
10 map<int,int> hash;
11 void init() {
12 memset(GPA,0,sizeof(GPA));
13 for(int i=60;i<=69;i++) hash[i]=1;
14 for(int i=70;i<=74;i++) hash[i]=2;
15 for(int i=75;i<=79;i++) hash[i]=3;
16 for(int i=80;i<=84;i++) hash[i]=4;
17 for(int i=85;i<=100;i++) hash[i]=5;
18 GPA[1]=2.0; GPA[2]=2.5; GPA[3]=3.0;
19 GPA[4]=3.5; GPA[5]=4.0;
20 memset(dp2,0,sizeof(dp2));
21 for(int i=0;i<=10;i++) {
22 for(int j=0;j<=1000;j++) dp1[i][j]=inf;
23 }
24 for(int i=60;i<=100;i++) {
25 dp1[1][i]=GPA[hash[i]];
26 dp2[1][i]=GPA[hash[i]];
27 }
28 for(int i=2;i<=10;i++) {
29 for(int v=0;v<=1000;v++) {
30 for(int j=60;j<=100;j++) {
31 if(v>=j) {
32 if(i==1) {
33 dp1[i][v]=min(dp1[i][v],dp1[i-1][v-j]+GPA[hash[j]]);
34 dp2[i][v]=max(dp2[i][v],dp2[i-1][v-j]+GPA[hash[j]]);
35 }
36 else if(((double)(v-j)/(double)(i-1))>=60) {
37 dp1[i][v]=min(dp1[i][v],dp1[i-1][v-j]+GPA[hash[j]]);
38 dp2[i][v]=max(dp2[i][v],dp2[i-1][v-j]+GPA[hash[j]]);
39 }
40 }
41 }
42 }
43 }
44
45
46 }
47 int main() {
48 int n,cnt,ave; init();
49 scanf("%d",&n);
50 while(n--) {
51 scanf("%d %d",&ave,&cnt);
52 int tot=ave*cnt;
53 printf("%.4lf %.4lf ",dp1[cnt][tot]/(double)cnt,dp2[cnt][tot]/(double)cnt);
54 }
55 return 0;
56 }
Improving the GPA
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 181 Accepted Submission(s): 148
Problem Description
Xueba: 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 many different possible values in the 4-Point Scale. Please calculate the minimum and maximum value of the GPA in the 4-Point Scale.
In fact, the AVERAGE SCORE of Xueba is calculated by the following formula:
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:
So given one student’s AVERAGE SCORE and the number of the courses, there are many different possible values in the 4-Point Scale. Please calculate the minimum and maximum value of the GPA in the 4-Point Scale.
Input
The 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).
Output
For each test case, you should 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
4 75 1 75 2 75 3 75 10
Sample Output
3.0000 3.0000 2.7500 3.0000 2.6667 3.1667 2.4000 3.2000
有是一道傻比dp,没判不合法情况逗比3小时才过。