题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970
4 75 1 75 2 75 3 75 10
3.0000 3.0000 2.7500 3.0000 2.6667 3.1667 2.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.6667 Scores 79 78 68 GPA = (3.0 + 3.0 + 2.0) / 3 = 2.6667 Scores 84 74 67 GPA = (3.5 + 2.5 + 2.0) / 3 = 2.6667 Scores 100 64 61 GPA = (4.0 + 2.0 + 2.0) / 3 = 2.6667
思路:
因为此题的N很小Score也最多才100,所以可以直接暴力每种状态时的分数和,看所给的总分是否在其中,再在所有满足的分数范围中找最小与最大的。
代码如下:
#include <cstdio> #define INF 1117 int main() { int t; int avg, n; int i1, j1, k1, l1; int i2, j2, k2, l2; scanf("%d",&t); while(t--) { double minn = INF, maxx = -INF; scanf("%d%d",&avg,&n); int sum = avg*n; for(int i = 0; i <= n; i++) { i1 = i*100; i2 = i*85; for(int j = 0; j <= n-i; j++) { j1 = j*84; j2 = j*80; for(int k=0; k <= n-i-j; k++) { k1 = k*79; k2 = k*75; for(int l = 0; l <= n-i-j-k; l++) { l1 = l*74; l2 = l*70; int tmp = n-i-j-k-l; int maxsum = i1+j1+k1+l1+tmp*69; int minsum = i2+j2+k2+l2+tmp*60; if(sum>=minsum && sum<=maxsum) { double tt = i*4 + j*3.5 + k*3.0 + l*2.5 + tmp*2; if(tt < minn) { minn = tt; } if(tt > maxx) { maxx = tt; } } } } } } printf("%.4lf %.4lf\n",minn/(n*1.0),maxx/(n*1.0)); } return 0; }
hdu 4968 Improving the GPA(暴力枚举),布布扣,bubuko.com
hdu 4968 Improving the GPA(暴力枚举)
原文地址:http://blog.csdn.net/u012860063/article/details/38687231