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>
 6 #include <algorithm>
 7 #define LL __int64
 8 const int maxn = 2000+10;
 9 const int INF = 1<<28;
10 using namespace std;
11
12 int main()
13 {
14     int t, i, j, k, l, m, sc, n, sum1, sum2, y;
15     double gp, ans1, ans2;
16     scanf("%d", &t);
17     while(t--)
18     {
19         ans1 = INF;
20         ans2 = -1;
21         scanf("%d%d", &sc, &n);
22         y = sc*n;
23
24         for(i = 0; i <= n; i++)
25             for(j = 0; j <= n-i; j++)
26                 for(k = 0; k <= n-i-j; k++)
27                     for(l = 0; l <= n-i-j-k; l++)
28                         for(m = 0; m <= n-i-j-k-l; m++)
29                         {
30                             if(i+j+k+l+m==n)
31                             {
32                                 //printf("%d %d %d %d %d\n", i, j, k, l, m);
33                                 sum1 = (i*60+j*70+k*75+l*80+m*85);
34                                 sum2 = (i*69+j*74+k*79+l*84+m*100);
35                                 gp = i*2+j*2.5+k*3+l*3.5+m*4;
36
37                                 if(y>=sum1&&y<=sum2)
38                                 {
39                                     if(gp<ans1) ans1 = gp;
40                                     if(gp>ans2) ans2 = gp;
41                                 }
42                             }
43                         }
44         //cout<<ans1<<endl;
45         ans1 = ans1*1.0/n;
46         ans2 = ans2*1.0/n;
47         printf("%.4lf %.4lf\n", ans1, ans2);
48     }
49     return 0;
50 }

hdu 4968 Improving the GPA (水 暴力枚举),布布扣,bubuko.com

时间: 2024-10-19 14:15:59

hdu 4968 Improving the GPA (水 暴力枚举)的相关文章

hdu 4968 Improving the GPA(暴力枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 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 S

HDU 4968 Improving the GPA 多校第九场1009

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

枚举一种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 ("

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 模拟

最小时就都当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

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 5616 Jam&#39;s balance(暴力枚举子集)

题目链接:点击打开链接 题意:有一个没有游标的天平,和n个秤砣,m个询问, 每次一个k,问可否秤出k这个重量. 秤砣可以放两边. 思路:因为n最大20, 暴力枚举子集. 因为可以放两边, 所以每次再跑一遍, 减去每个的重量, 将答案保存. 比赛的时候忘了限制边界,虽然过了终测数据, 却被人用大数据hack了(RE), 还是自己程序写的不够鲁棒, 思考的不完善. 细节参见代码: #include<cstdio> #include<cstring> #include<algori