标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 206 Accepted Submission(s):
168
#include<stdio.h> #include<string.h> int l[5]= {60,70,75,80,85}; int r[5]= {69,74,79,84,100}; double gpa[5]= {2.0,2.5,3.0,3.5,4.0}; int avg,N,sum,P,Q; double maxgpa,mingpa; bool flag; void dfs1(int t1,int t2,int a,int b,double c) { if(flag) return ; if(t2==0&&a<=sum&&b>=sum) { mingpa=c; flag=true; return ; } if(t1>4||t2==0) return ; for(int i=t2; i>=0; i--) { dfs1(t1+1,t2-i,a+l[t1]*i,b+r[t1]*i,c+gpa[t1]*i); } } void dfs2(int t1,int t2,int a,int b,double c) { if(flag) return ; if(t2==0&&a<=sum&&b>=sum) { maxgpa=c; flag=true; return ; } if(t1<0||t2==0) return ; for(int i=t2; i>=0; i--) { dfs2(t1-1,t2-i,a+l[t1]*i,b+r[t1]*i,c+gpa[t1]*i); } } int main() { int T,i,j,k,l; scanf("%d",&T); while(T--) { scanf("%d%d",&avg,&N); sum=avg*N; maxgpa=mingpa=0; flag=false; dfs1(0,N,0,0,0); flag=false; dfs2(4,N,0,0,0); printf("%.4lf %.4lf\n",mingpa/N,maxgpa/N); } return 0; }
dfs自己还用的不是很好,比赛的时候等我写完,我们队的其他人已经过了。。。。。
Improving the GPA(hdu4968)dfs,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/yuyixingkong/p/3923958.html