暴力失败,谁能贴一份ac代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
using namespace std;

const int N = 2*1e5+5;
struct student{
    string name;
    int n1;
    int a2;
    int a3;
    int a4;
    int a5;
    double sum;
}stu[N];
double maxScore[5];

bool cmp(student a, student b){
    double c = a.sum - b.sum;
    if(c<0)
        c = -c;
    if(c>1e-5){
        return a.sum>b.sum;
    }else{
        return a.name < b.name;
    }
}
int main()
{
    int n;
    while(cin>>n)
    {

        for(int i=1;i<=n;i++){
            double c1,c2,c3,c4, c5;
            //scanf("%s %lf %lf %lf %lf %lf", &stu[i-1].name,&c1,&c2,&c3,&c4, &c5);
            cin>>stu[i-1].name>>c1>>c2>>c3>>c4>>c5;
            stu[i-1].n1 = c1;
            stu[i-1].a2 = c2;
            stu[i-1].a3 = c3;
            stu[i-1].a4 = c4;
            stu[i-1].a5 = c5;
            if(c1>maxScore[0])
            {
                maxScore[0] = c1;
            }
            if(c2>maxScore[1])
            {
                maxScore[1] = c2;
            }
            if(c3>maxScore[2])
            {
                maxScore[2] = c3;
            }
            if(c4>maxScore[3])
            {
                maxScore[3] = c4;
            }
            if(c5>maxScore[4])
            {
                maxScore[4] = c5;
            }
        }

        //2
        for(int i=0; i<n;i++){
            stu[i].sum = 0;
            stu[i].sum += (stu[i].n1*600/maxScore[0])*0.25;
            stu[i].sum += (stu[i].a2*300/maxScore[1] + stu[i].a3*300/maxScore[2])*0.25;
            stu[i].sum += (stu[i].a4*300/maxScore[3] + stu[i].a5*300/maxScore[4])*0.5;
            //printf("%.5lf ", stu[i].sum);
        }
        //3.sort
        sort(stu, stu+n, cmp);
        //4.printf
            for(int i=0; i<n;i++){
            cout<<stu[i].name;
            printf(" %.5lf\n",stu[i].sum);
        }
    }
    return 0;
}

全部评论
你这个似乎maxScore没有更新吧,数据有多组🧐
点赞 回复 分享
发布于 2020-07-17 17:44

相关推荐

完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务