竞赛讨论区 > 暴力失败,谁能贴一份ac代码
头像
xq17
发布于 2020-03-14 14:17
+ 关注

暴力失败,谁能贴一份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;
}

全部评论

(1) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐