现在有一个有趣的问题,给出某人每门课的学分和成绩,问在平均分一样的情况下,平均GPA最高能达到多少。假设每门课的成绩必须是[60, 100]之间的整数。
Input:
第一行是一个整数t (1<=t<=100), 表示有t组测试数据。
每组测试数据的第一行是一个整数n(1<=n<=10),表示本组数据有n门课。接下来的n行每行包括一个实数f和整数p,表示每门课的学分和成绩,用一个空格隔开。(f只可能是0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6中的一个,60<=p<=100 )
Output:
对每组数据输出一行,该行包含一个实数,表示加权平均分一样的条件下平均GPA的最大值, 四舍五入,保留两位小数。
Sample Input:
3
2
3 91
2 89
3
2 63
3 60
5 62
4
3.5 76
3.5 81
2 77
2.5 78
Sample Output:
3.94
1.34
3.00
Hint:
第一组数据的一个解是:87,95
第二组数据的一个解是:64,61,61
第三组数据的一个解是:85,78,79,68
百分制 五等级制 学分绩点
100~95 A+ 4.3
94~90 A 4
89~85 A- 3.7
84~82 B+ 3.3
81~78 B 3
77~75 B- 2.7
74~72 C+ 2.3
71~68 C 2
67~65 C- 1.7
64 D+ 1.5
63~61 D 1.3
60 D- 1
5 个解决方案
#1
float a=35*76+35*81+20*77+25*81;
float b=35*85+35*78+20*79+25*68;
float c=(3.5*3.7+3.5*3+2*3+2.5*2)/(3.5+3.5+2+2.5);
int n,m;
int i,j;
printf("%f %f %f",a,b,c);
输出:
G:\projects>test
9060.000000 8985.000000 2.995652
可见"第三组数据的一个解是:85,78,79,68"是错误的,这两组数据的加权总分(平均分)不同;
float b=35*85+35*78+20*79+25*68;
float c=(3.5*3.7+3.5*3+2*3+2.5*2)/(3.5+3.5+2+2.5);
int n,m;
int i,j;
printf("%f %f %f",a,b,c);
输出:
G:\projects>test
9060.000000 8985.000000 2.995652
可见"第三组数据的一个解是:85,78,79,68"是错误的,这两组数据的加权总分(平均分)不同;
#2
#include <stdio.h>
int range[12][3]={
{100,95,43},
{94,90,40},
{89,85,37},
{84,82,33},
{81,78,30},
{77,75,27},
{74,72,23},
{71,68,20},
{67,65,17},
{64,64,15},
{63,61,13},
{60,60,10}
};
int max_value;
int n,m;
int *ip,*sp,*max_ip;
float getvalue(int score)
{
int i;
for (i=0;i<12 ;++i )
{
if (score>=range[i][1]) break;
}
return range[i][2];
}
void calc(int idx,int sum_score,int value)
{
int i;
if (idx==m-1 || sum_score<=0)
{
int tmp_score=sum_score / sp[idx];
if (sum_score % sp[idx]==0 && tmp_score>=60 && tmp_score<=100)
{
value+=getvalue(tmp_score)*sp[idx];
ip[idx]=tmp_score;
if (value>max_value)
{
max_value=value;
for (i=0;i<m ;++i ) max_ip[i]=ip[i];
}
}
return;
}
for (i=0; i<12;++i )
{
ip[idx]=range[i][1];
calc(idx+1,sum_score-range[i][1]*sp[idx],value+range[i][2]*sp[idx]);
}
}
int main(int argc,char * argv[])
{
int i,j;
scanf("%d",&n);
while(n--)
{
int sum_score,sum_sp;
float score;
scanf("%d",&m);
i=m;
sp=(int *)malloc(m*sizeof(int));
ip=(int *)malloc(m*sizeof(int));
max_ip=(int *)malloc(m*sizeof(int));
i=0;
sum_score=0;
sum_sp=0;
while(i<m)
{
scanf("%f %d",&score,ip+i);
sp[i]=score*10;
sum_score+=sp[i]*ip[i];
sum_sp+=sp[i];
++i;
}
max_value=0;
calc(0,sum_score,0);
printf("\nmax:%.2f \none solution:",max_value*1.0/(10*sum_sp));
for (i=0;i<m ; ++i) printf("%d ",max_ip[i]);
printf("\n");
}
return 0;
}
int range[12][3]={
{100,95,43},
{94,90,40},
{89,85,37},
{84,82,33},
{81,78,30},
{77,75,27},
{74,72,23},
{71,68,20},
{67,65,17},
{64,64,15},
{63,61,13},
{60,60,10}
};
int max_value;
int n,m;
int *ip,*sp,*max_ip;
float getvalue(int score)
{
int i;
for (i=0;i<12 ;++i )
{
if (score>=range[i][1]) break;
}
return range[i][2];
}
void calc(int idx,int sum_score,int value)
{
int i;
if (idx==m-1 || sum_score<=0)
{
int tmp_score=sum_score / sp[idx];
if (sum_score % sp[idx]==0 && tmp_score>=60 && tmp_score<=100)
{
value+=getvalue(tmp_score)*sp[idx];
ip[idx]=tmp_score;
if (value>max_value)
{
max_value=value;
for (i=0;i<m ;++i ) max_ip[i]=ip[i];
}
}
return;
}
for (i=0; i<12;++i )
{
ip[idx]=range[i][1];
calc(idx+1,sum_score-range[i][1]*sp[idx],value+range[i][2]*sp[idx]);
}
}
int main(int argc,char * argv[])
{
int i,j;
scanf("%d",&n);
while(n--)
{
int sum_score,sum_sp;
float score;
scanf("%d",&m);
i=m;
sp=(int *)malloc(m*sizeof(int));
ip=(int *)malloc(m*sizeof(int));
max_ip=(int *)malloc(m*sizeof(int));
i=0;
sum_score=0;
sum_sp=0;
while(i<m)
{
scanf("%f %d",&score,ip+i);
sp[i]=score*10;
sum_score+=sp[i]*ip[i];
sum_sp+=sp[i];
++i;
}
max_value=0;
calc(0,sum_score,0);
printf("\nmax:%.2f \none solution:",max_value*1.0/(10*sum_sp));
for (i=0;i<m ; ++i) printf("%d ",max_ip[i]);
printf("\n");
}
return 0;
}
#3
尾巴 居然跑这里来了啊 ^_^
楼主还在搞 ACM ??
楼主还在搞 ACM ??
#4
c版捞分不容易呀,来这里找点补贴.
#5
最好捞的是VC/MFC,那边的兄弟慷慨!
C般打了很多字只给几分!
很受伤!
C般打了很多字只给几分!
很受伤!
#1
float a=35*76+35*81+20*77+25*81;
float b=35*85+35*78+20*79+25*68;
float c=(3.5*3.7+3.5*3+2*3+2.5*2)/(3.5+3.5+2+2.5);
int n,m;
int i,j;
printf("%f %f %f",a,b,c);
输出:
G:\projects>test
9060.000000 8985.000000 2.995652
可见"第三组数据的一个解是:85,78,79,68"是错误的,这两组数据的加权总分(平均分)不同;
float b=35*85+35*78+20*79+25*68;
float c=(3.5*3.7+3.5*3+2*3+2.5*2)/(3.5+3.5+2+2.5);
int n,m;
int i,j;
printf("%f %f %f",a,b,c);
输出:
G:\projects>test
9060.000000 8985.000000 2.995652
可见"第三组数据的一个解是:85,78,79,68"是错误的,这两组数据的加权总分(平均分)不同;
#2
#include <stdio.h>
int range[12][3]={
{100,95,43},
{94,90,40},
{89,85,37},
{84,82,33},
{81,78,30},
{77,75,27},
{74,72,23},
{71,68,20},
{67,65,17},
{64,64,15},
{63,61,13},
{60,60,10}
};
int max_value;
int n,m;
int *ip,*sp,*max_ip;
float getvalue(int score)
{
int i;
for (i=0;i<12 ;++i )
{
if (score>=range[i][1]) break;
}
return range[i][2];
}
void calc(int idx,int sum_score,int value)
{
int i;
if (idx==m-1 || sum_score<=0)
{
int tmp_score=sum_score / sp[idx];
if (sum_score % sp[idx]==0 && tmp_score>=60 && tmp_score<=100)
{
value+=getvalue(tmp_score)*sp[idx];
ip[idx]=tmp_score;
if (value>max_value)
{
max_value=value;
for (i=0;i<m ;++i ) max_ip[i]=ip[i];
}
}
return;
}
for (i=0; i<12;++i )
{
ip[idx]=range[i][1];
calc(idx+1,sum_score-range[i][1]*sp[idx],value+range[i][2]*sp[idx]);
}
}
int main(int argc,char * argv[])
{
int i,j;
scanf("%d",&n);
while(n--)
{
int sum_score,sum_sp;
float score;
scanf("%d",&m);
i=m;
sp=(int *)malloc(m*sizeof(int));
ip=(int *)malloc(m*sizeof(int));
max_ip=(int *)malloc(m*sizeof(int));
i=0;
sum_score=0;
sum_sp=0;
while(i<m)
{
scanf("%f %d",&score,ip+i);
sp[i]=score*10;
sum_score+=sp[i]*ip[i];
sum_sp+=sp[i];
++i;
}
max_value=0;
calc(0,sum_score,0);
printf("\nmax:%.2f \none solution:",max_value*1.0/(10*sum_sp));
for (i=0;i<m ; ++i) printf("%d ",max_ip[i]);
printf("\n");
}
return 0;
}
int range[12][3]={
{100,95,43},
{94,90,40},
{89,85,37},
{84,82,33},
{81,78,30},
{77,75,27},
{74,72,23},
{71,68,20},
{67,65,17},
{64,64,15},
{63,61,13},
{60,60,10}
};
int max_value;
int n,m;
int *ip,*sp,*max_ip;
float getvalue(int score)
{
int i;
for (i=0;i<12 ;++i )
{
if (score>=range[i][1]) break;
}
return range[i][2];
}
void calc(int idx,int sum_score,int value)
{
int i;
if (idx==m-1 || sum_score<=0)
{
int tmp_score=sum_score / sp[idx];
if (sum_score % sp[idx]==0 && tmp_score>=60 && tmp_score<=100)
{
value+=getvalue(tmp_score)*sp[idx];
ip[idx]=tmp_score;
if (value>max_value)
{
max_value=value;
for (i=0;i<m ;++i ) max_ip[i]=ip[i];
}
}
return;
}
for (i=0; i<12;++i )
{
ip[idx]=range[i][1];
calc(idx+1,sum_score-range[i][1]*sp[idx],value+range[i][2]*sp[idx]);
}
}
int main(int argc,char * argv[])
{
int i,j;
scanf("%d",&n);
while(n--)
{
int sum_score,sum_sp;
float score;
scanf("%d",&m);
i=m;
sp=(int *)malloc(m*sizeof(int));
ip=(int *)malloc(m*sizeof(int));
max_ip=(int *)malloc(m*sizeof(int));
i=0;
sum_score=0;
sum_sp=0;
while(i<m)
{
scanf("%f %d",&score,ip+i);
sp[i]=score*10;
sum_score+=sp[i]*ip[i];
sum_sp+=sp[i];
++i;
}
max_value=0;
calc(0,sum_score,0);
printf("\nmax:%.2f \none solution:",max_value*1.0/(10*sum_sp));
for (i=0;i<m ; ++i) printf("%d ",max_ip[i]);
printf("\n");
}
return 0;
}
#3
尾巴 居然跑这里来了啊 ^_^
楼主还在搞 ACM ??
楼主还在搞 ACM ??
#4
c版捞分不容易呀,来这里找点补贴.
#5
最好捞的是VC/MFC,那边的兄弟慷慨!
C般打了很多字只给几分!
很受伤!
C般打了很多字只给几分!
很受伤!