标签:style blog http color os io for ar
题意:给你平均分数,让你给出可能的最大的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
标签:style blog http color os io for ar
原文地址:http://www.cnblogs.com/zyue/p/3923577.html