厦大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;
}

最近更新

  1. TCP协议是安全的吗?

    2024-03-16 19:46:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-16 19:46:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-16 19:46:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-16 19:46:02       18 阅读

热门阅读

  1. 452. 用最少数量的箭引爆气球

    2024-03-16 19:46:02       20 阅读
  2. 常用的正则表达式

    2024-03-16 19:46:02       18 阅读
  3. Redis 线程模型

    2024-03-16 19:46:02       20 阅读
  4. springboot2.7使用redis的redission组件实现分布式锁

    2024-03-16 19:46:02       16 阅读
  5. MySQL作业一

    2024-03-16 19:46:02       19 阅读
  6. Linux用户和权限

    2024-03-16 19:46:02       16 阅读
  7. 力扣98:验证二叉搜索树

    2024-03-16 19:46:02       17 阅读
  8. Horspool 算法介绍

    2024-03-16 19:46:02       18 阅读