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 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25
26 using namespace std;
27 int num[10];
28 int mxsco[] = {100,84,79,74,69};
29 int misco[] = {85,80,75,70,60};
30 double sc[] = {4.0,3.5,3.0,2.5,2.0};
31 int sco,n,lsco;
32 double ansmi,ansmx;
33 void dfs(int k , int lnum,int mx,int mi,double tsc)
34 {
35     //printf("%d %d\n",mx,mi);
36     if(k == 5 )
37     {
38        //printf("%d %d\n",mx,mi);
39        if(lsco <= mx && lsco >= mi && lnum == 0 )
40        {
41          if(tsc < ansmi)
42              ansmi = tsc;
43          if(tsc > ansmx)
44          {
45             /* printf("%d %d\n",mx,mi);
46              for(int i = 0;i < 5;i ++)
47                  printf("%d ",num[i]);
48              printf("\n");*/
49              ansmx = tsc;
50          }
51        }
52        return;
53     }
54     if(lsco < mi)
55         return;
56     for(int i = 0 ;i <= lnum ;i ++)
57     {
58         num[k] = i ;
59         dfs(k+1,lnum-i,mx+i*mxsco[k],mi+i*misco[k], tsc+i*sc[k]);
60     }
61 }
62 int main(){
63    int T;
64    scanf("%d",&T);
65    while(T--)
66    {
67      scanf("%d %d",&sco,&n);
68      lsco = sco*n;
69      ansmi = 1e10;
70      ansmx = -1e10;
71      dfs(0,n,0,0,0.0);
72      printf("%.4lf %.4lf\n",ansmi/n,ansmx/n);
73    }
74 return 0;
75 }

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

时间: 2024-09-29 09:26:59

HDU4968 Improving the GPA dfs的相关文章

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

【瞎搞】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 ("

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