厦大GPA(xmuoj)

厦大GPA

描述

厦门大学的GPA (绩点)计算规则一直是同学们非常关心的问题。每门考试成绩为百分制,则分数与绩点对应关系如下:

90~100 4.0

85~89 3.7

81~84 3.3

78~80 3.0

75~77 2.7

72~74 2.3

68~71 2.0

64~67 1.7

60~63 1.0

0~59 0.0

某位同学一共参加了4门考试,给定四门考试的总分,请问在最优情况下,4门考试绩点的和最高是多少?

输入

输入4门考试的总分n,0≤n≤400。

400
359
59

输出

输出最优情况下,4门考试绩点之和的最高值。结果保留一位小数。

16.0
15.7
0.0

代码实现:

#include<iostream>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;
class MyComp
{//让map按照绩点降序排序
public:
    bool operator()(float v1,float v2)
    {
        return v1>v2;
    }
};
float getGPA(int score)
{
    // 绩点与分数的对应关系
    if (score >= 90) return 4.0;
    else if (score >= 85) return 3.7;
    else if (score >= 81) return 3.3;
    else if (score >= 78) return 3.0;
    else if (score >= 75) return 2.7;
    else if (score >= 72) return 2.3;
    else if (score >= 68) return 2.0;
    else if (score >= 64) return 1.7;
    else if (score >= 60) return 1.0;
    else return 0.0;
}
map<float,int,MyComp> m;
int line[10]={90,85,81,78,75,72,68,64,60,0};
void make_table()
{
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
        {
            for(int k=0;k<10;k++)
            {
                for(int d=0;d<10;d++)
                {
                    int total=line[i]+line[j]+line[k]+line[d];
                    float gpa=getGPA(line[i])+getGPA(line[j])+getGPA(line[k])+getGPA(line[d]);
                    map<float,int,MyComp>::iterator it=m.find(gpa);
                    if(it==m.end())
                    {
                        m.insert(make_pair(gpa,total));
                    }
                    else
                    {
                        if(it->second>total)it->second=total;
                    }
                }
            }
        }
    }
}
float Get_MAX(int score);
int main()
{
    make_table();
    int total;
    while(cin>>total)
    {
        float res=Get_MAX(total);
        cout<<fixed<<setprecision(1)<<res<<endl;
    }
    return 0;
}
float Get_MAX(int score)
{
    map<float,int,MyComp>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        if(it->second<=score)return it->first;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值