码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-19 22:21:26      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

题目链接

题意:给平均成绩和科目数,求可能的最大学分和最小学分。

分析:

bubuko.com,布布扣

枚举一下,可以达到复杂度可以达到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

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

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/bfshm/p/3923146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!