HDU4968-Improving the GPA

题目链接

题意:每个成绩范围对应一个绩点,给出平均分avg,课程数n,求能得到的平均绩点的最大值和最小值。

思路:先预处理出每个成绩所对应的绩点,然后递推出所有情况,d[i][k]表示i个人有k分的绩点总数,所以可以得到动态转移方程。

当求最大值时d[i][k] = max(d[i][k], d[i - 1][k - j] + gpa[j])(j表示课程分数)

当求最小值时d[i][k] = min(d[i][k], d[i - 1][k - j] + gpa[j])(j表示课程分数)

注意初始化就可以了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 1005;
const int INF = 100000.0;

double dp1[15][MAXN], dp2[15][MAXN];
double gpa[MAXN];

void init() {
    for (int i = 60; i <= 69; i++)
        gpa[i] = 2.0;
    for (int i = 70; i <= 74; i++)
        gpa[i] = 2.5;
    for (int i = 75; i <= 79; i++)
        gpa[i] = 3.0;
    for (int i = 80; i <= 84; i++)
        gpa[i] = 3.5;
    for (int i = 85; i <= 100; i++)
        gpa[i] = 4.0;
}

void solve() {
    memset(dp1, 0, sizeof(dp1));
    for (int i = 60; i <= 100; i++)
        dp1[1][i] = gpa[i];
    for (int i = 2; i <= 10; i++)
        for (int j = 60; j <= 100; j++)
            for (int k = j; k <= MAXN; k++)
                if (dp1[i - 1][k - j] != 0)
                    dp1[i][k] = max(dp1[i][k], dp1[i - 1][k - j] + gpa[j]);

    for (int i = 0; i <= 10; i++)
        for (int j = 0; j <= MAXN; j++)
            dp2[i][j] = INF;
    for (int i = 60; i <= 100; i++)
        dp2[1][i] = gpa[i];
    for (int i = 2; i <= 10; i++)
        for (int j = 60; j <= 100; j++)
            for (int k = j; k <= MAXN; k++)
                if (dp2[i - 1][k - j] != INF)
                    dp2[i][k] = min(dp2[i][k], dp2[i - 1][k - j] + gpa[j]);
}

int main() {
    int cas;
    scanf("%d", &cas);
    init();
    solve();
    while (cas--) {
        int avg, n;
        scanf("%d%d", &avg, &n);
        printf("%.4lf %.4lf\n", dp2[n][avg * n] / n, dp1[n][avg * n] / n);
    }
    return 0;
}

HDU4968-Improving the GPA,布布扣,bubuko.com

时间: 2024-08-07 07:59:18

HDU4968-Improving the GPA的相关文章

HDU4968 Improving the GPA dfs

题意:给你平均分数,让你给出可能的最大的gpa和最小的gpa 解题思路:最开始因为误判了时间复杂度所以没敲,敲完1002以后发现一个dfs就可以解决了,枚举0 - 100000表示每个档次有多少科,最后算下总分是不是可能就行,dfs减枝会略微的快一点. 1 // File Name: 1009.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月19日 星期二 12时16分48秒 4 5 #include<vector> 6 #inclu

HDU4968:Improving the GPA(DP)

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

Improving the GPA(hdu4968)dfs

Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 206 Accepted Submission(s): 168 Problem Description Xueba: Using the 4-Point Scale, my GPA is 4.0. In fact, the AVERAGE SCORE of

HDOJ 4968 Improving the GPA

枚举... Improving the GPA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 158    Accepted Submission(s): 126 Problem Description Xueba: Using the 4-Point Scale, my GPA is 4.0. In fact, the AVER

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

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

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 4968 Improving the GPA 模拟

最小时就都当69,最大时都当85 .. #include <cstdio> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <vector> #include <map> #include <queue> using namespace std; #define N 5000 int

【瞎搞】HDU 4968 Improving the GPA

枚举一种GPA有多少个 总分1加上该GPA的最小分数 总分2加上该GPA的最大分数 若总分1<=输入分数×n<=总分2 则可以在枚举的状态达到目标分数 #include <stdio.h> #include <string.h> #include <math.h> #include <string> #include <algorithm> using namespace std; #define IN freopen ("