HDU 4968 (水dp 其他?)

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\n",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.

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小时才过。

HDU 4968 (水dp 其他?),布布扣,bubuko.com

时间: 2024-10-27 12:35:49

HDU 4968 (水dp 其他?)的相关文章

hdu 4856 水dp

别看像搜索    试试就超时 ==,    想想还是用dp做吧: 因为只能从三个方向走   ,对于第一列只能从上往下走  所以很快就能求出第一列的dp[i][j] 到达表示这个位置的最大金币,对以后的每一列  先从左边过来更新一次,,,再有两种走法,往下走和往上走,用两个数组分别记下最大值   然后从这两个中找出最大值: #include<stdio.h> #include<string.h> #include<iostream> using namespace std

HDU 4960 (水dp)

Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi

hdu 4968 Improving the GPA dp

[题意]:每个成绩范围对应一个绩点,给出平均分avg,课程数n,求能得到的平均绩点的最大值和最小值. [解法]:   d[i][j]表示总分为i 课程数为j时 可以得到的最大的总绩点. 状态转移为: d[i][j]=max(d[i][j],d[i-k][j-1]+d[k][1]);   (60<=k<=100&&i-k>=60*(j-1)) 1 #include<iostream> 2 #include<cstdio> 3 #include<

HDU 4968 Improving the GPA(dp)

HDU 4968 Improving the GPA 题目链接 dp,最大最小分别dp一次,dp[i][j]表示第i个人,还有j分的情况,分数可以减掉60最为状态 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int t, avg, n; double dp1[15][405], dp2[15][405]; double get(int x) { if

hdu 4968 Improving the GPA (水 暴力枚举)

题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10,但是这个又不要求顺序,所以只是枚举个数就行了.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath&g

hdu 4405 概率dp 2012年金华亚洲网络赛--虽然水,但是是自己独立做的第一道概率dp

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4405 e[i]:当前在位置i还需要走的步数期望 受刘汝佳的AC自动机那个后缀链接写法的启发,我的x[i]通过逆序算出来连续有"flight line "的时候,能到达的最远距离, rep(i,0,m) { scanf("%d%d",&xx,&yy); x[xx]=yy; } for(int i=n;i>=0;i--) if(x[i]!=-1 &

hdu 2571 命运(水DP)

题意: M*N的grid,每个格上有一个整数. 小明从左上角(1,1)打算走到右下角(M,N). 每次可以向下走一格,或向右走一格,或向右走到当前所在列的倍数的列的位置上.即:若当前位置是(i,j),可以走到(i,k*j) 问取走的最大和是多少. 思路: 水DP...边界的初始化要考虑.(因为有负数). 代码: int n,m; int a[30][1005]; int dp[30][1005]; int main(){ int T; cin>>T; while(T--){ cin>&g

HDU 2084 数塔 (水DP)

题意:.... 析:从下往上算即可,水DP. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <

hdu5074 Hatsune Miku 2014鞍山现场赛E题 水dp

http://acm.hdu.edu.cn/showproblem.php?pid=5074 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 325    Accepted Submission(s): 243 Problem Description Hatsune Miku is a popular vi