GPA
description |
我们都知道加权平均成绩是AVERAGE SCORE = ∑(Wi * SCORE[i]) / ∑(Wi) , 1<=i<=N这么算的,那么假如现在每门课的学分都为1,AVERAGE SCORE =∑(SCORE[i]) / N , 1<=i<=N。另外,SCORE[i]在60到100之间。在NEFU,除了加权平均成绩,我们还用绩点,即GPA来评价一个学生,成绩所对应的相应绩点如下: SCORE[i] GPA[i] 85-100 4 80-84 3.5 75-79 3.0 70-74 2.5 60-69 2.0 一个学生的平均学分绩点GPA = ∑(GPA[i]) / N , 1<=i<=N。 现在给你某个学生的平均成绩AVERAGE SCORE和他修的课程总数 N,所以他每门课的分数是不确定的,也就是每门课的绩点是不确定的,那么请你算出他的最大GPA和最小GPA。 |
input |
|
output |
|
sample_input |
|
sample_output
这题典型的暴力枚举,主要是遍历,时间充足的话完全可以,代码好懂,思考过程不简单,下面附上代码仅供参考:#include <iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
int n,avr;
while(scanf("%d%d",&avr,&n)!=EOF)
{
double max0=2,min0=4,x;
int s=avr*n;
for(int a1=0;a1<=s/85;a1++)
{
for(int a2=0;a2<=s/80;a2++)
{
for(int a3=0;a3<=s/75;a3++)
{
for(int a4=0;a4<=s/70;a4++)
{
for(int a5=0;a5<=s/60;a5++)
{
if(a1*85+a2*80+a3*75+a4*70+a5*60<=s&&a1*100+a2*84+a3*79+a4*74+a5*69>=s&&a1+a2+a3+a4+a5==n)
{x=(a1*4+a2*3.5+a3*3+a4*2.5+a5*2)/n*1.0;
if(x>max0)
max0=x;
if(x<min0)
min0=x;
}
}
}
}
}
}
printf("%.4f %.4f\n",min0,max0);
}
return 0;
}
|
持续更新博客地址:
blog.csdn.net/martinue

浙公网安备 33010602011771号