题解 P7426 [THUPC 2017] 体育成绩统计

· · 题解

前言

由于作者喜欢使用 define 和 using 定义一些东西来方便快速写代码,所以在一切的前面先把缺省源放出来,方便读者理解后续作者编写的代码。

题意简述

大模拟一般来说仔细阅读原题面比较好,这里我给出一个简要的说明:你需要编写一个体育成绩统计系统,题目输入会给你若干个学生的各种信息,要求你分析每个学生最后的分数以及等级并且输出。

题目分析

我们一步一步来分析和拆解步骤。众所周知,一个大模拟的过程是输入,模拟,输出,在接下来的过程中会分步分析。

Part 0. 准备工作

在开始编写所有东西之前,我们需要有以下几个东西方便我们后续的编写和调代码:

0. 为了方便我们在后续调试的过程中看懂自己在写什么,建议采用良好的命名方式,比如大驼峰,并适当编写注释;同时我们也应该有一个方便我们调试代码的输出工具,你可以选择自己编写或者使用封装好的,作者使用的是 tourist 的 debug 工具改编,作者在编写代码时有时还会使用 assert 与 cerr 来帮助调试,二者的具体用法可以自行查询,作者的代码中保留了所有调试信息。

//debug 工具 from tourist
#ifdef ONLINE_JUDGE
//when on OJ,close the debug version
#undef Debug
#define Debug(...) 42
#else
//open debug version.
#define register
#define cerr cout
#define Debug(...) cerr << "Debug " << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
template<typename A,typename B>string to_string(pair<A,B>p);
template<typename A,typename B,typename C>string to_string(tuple<A,B,C>p);
template<typename A,typename B,typename C,typename D>string to_string(tuple<A,B,C,D>p);
string to_string(const string&s){return'"'+s+'"';}
string to_string(const char*s){return to_string((string)s);}
string to_string(bool b){return(b?"true":"false");}
string to_string(vector<bool>v){bool first=true;string res="{";for(int i=0;i<static_cast<int>(v.size());i++){if(!first){res+=", ";}first=false;res+=to_string(v[i]);}res+="}";return res;}
template<size_t N>string to_string(bitset<N>v){string res="";for(size_t i=0;i<N;i++){res+=static_cast<char>('0'+v[i]);}return res;}
template<typename A>string to_string(A v){bool first=true;string res="{";for(const auto&x:v){if(!first){res+=", ";}first=false;res+=to_string(x);}res+="}";return res;}
template<typename A,typename B>string to_string(pair<A,B>p){return"("+to_string(p.first)+", "+to_string(p.second)+")";}
template<typename A,typename B,typename C>string to_string(tuple<A,B,C>p){return"("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+")";}
template<typename A,typename B,typename C,typename D>string to_string(tuple<A,B,C,D>p){return"("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+", "+to_string(get<3>(p))+")";}
inline void debug_out(){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(Head H,Tail...T){cerr<<" "<<to_string(H);debug_out(T...);}
#endif

1. 本题中我们需要维护学生的信息,而最重要也是最复杂的东西也就是阳光长跑,为了方便维护阳光长跑并进行后面的各种操作,定义一个阳光长跑的结构无疑是重要的。

struct SunRun{
    string date;tp dateMon,dateDay,dateNum;
    tp ind;string sInd;
    string timeBeg,timeEnd;
    tp timeBegHour,timeBegMin,timeBegSec,timeBegTime;
    tp timeEndHour,timeEndMin,timeEndSec,timeEndTime;
    d64 dis;
    string stopTime;
    tp stopTimeMin,stopTimeSec,stopTimeTime;
    tp step;
    inline void Print(){
        Debug(ind);
        Debug(date,dateMon,dateDay,dateNum);
        Debug(timeBeg,timeBegHour,timeBegMin,timeBegSec,timeBegTime);
        Debug(timeEnd,timeEndHour,timeEndMin,timeEndSec,timeEndTime);
        Debug(dis,stopTime,stopTimeMin,stopTimeSec,stopTimeTime,step);return void();
    }
}Data[200200];

虽然作者的变量名比较规范,但为了防止歧义此处还是给出每个变量具体的含义:

2. 在维护阳光长跑的信息以后,我们就可以维护学生的信息了。

struct Student{
    tp ind;string sInd;
    tp gender;//M->1 F->0
    tp sportScore;
    string runScore;tp runMin,runSec,runTime;
    tp passFitness;//P->1 F->0
    tp planScore;
    tp classTrain;
    tp sunLegalCnt;
    tp finalScore;
    vc<SunRun>G,V;
    inline void Print(){
        Debug(ind,gender,sportScore);
        Debug(runScore,runMin,runSec,runTime);
        Debug(passFitness,planScore,classTrain,sunLegalCnt);
        for(auto&x:V)x.Print();return void(),void(),void() ;
    }
}a[20020];

同理为了防止歧义此处给出每个变量具体的含义:

3. 除了这些信息以外,通过阅读题目我们发现一些难处理的地方,比如阳光长跑和学生的信息是分开的,这是一个很麻烦的地方,阳光长跑给出的信息是学生的学号,为了能从学号直接定位到学生,我们可以开一个 map 来实现;不仅如此,我们还需要考虑如何处理烦人的日期,那么由于年份一定是 2017,所以我们可以考虑把月份全部转换成天数,以避免类似六月一日和五月三十一日比大小的这种棘手问题;对于时间比大小或者计算相差多少秒也是同理,全部转化成秒即可。

map<tp,Student>mp;//ind to student
vc<Student>Ans;//sort at the end
constexpr tp monthDay[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
inline tp transSec(tp Hour,tp Minute,tp Second){return Hour*3600+Minute*60+Second;}

4. 接下来只要再处理一下几个项目的评分标准就好了,这个是简单的,认真按照题目核对写代码即可。

inline tp getRunScore(tp gender,tp runTime){
    if(gender==1){//boys
        if(runTime<=transSec(0,12,30))return 20;
        if(runTime<=transSec(0,13,0 ))return 18;
        if(runTime<=transSec(0,13,30))return 16;
        if(runTime<=transSec(0,14,0 ))return 14;
        if(runTime<=transSec(0,14,30))return 12;
        if(runTime<=transSec(0,15,10))return 10;
        if(runTime<=transSec(0,15,50))return  8;
        if(runTime<=transSec(0,16,30))return  6;
        if(runTime<=transSec(0,17,10))return  4;
        if(runTime<=transSec(0,18, 0))return  2;
        return 0;
    }
    if(gender==0){//girls
        if(runTime<=transSec(0,6,40))return 20;
        if(runTime<=transSec(0,6,57))return 18;
        if(runTime<=transSec(0,7,14))return 16;
        if(runTime<=transSec(0,7,31))return 14;
        if(runTime<=transSec(0,7,50))return 12;
        if(runTime<=transSec(0,8, 5))return 10;
        if(runTime<=transSec(0,8,20))return  8;
        if(runTime<=transSec(0,8,35))return  6;
        if(runTime<=transSec(0,8,50))return  4;
        if(runTime<=transSec(0,9, 0))return  2;
        return 0;
    }
    return 114;
}
inline tp getSunRunScore(tp times){
    if(times>=21)return 10;
    if(times>=19)return  9;
    if(times>=17)return  8;
    if(times>=14)return  7;
    if(times>=11)return  6;
    if(times>= 7)return  4;
    if(times>= 3)return  2;
    return 0;
}
inline tp getAttScore(tp timesSunRun,tp timesClassTrain){
    tp sum=timesSunRun+timesClassTrain;
    if(sum>=18)return 5;
    if(sum>=15)return 4;
    if(sum>=12)return 3;
    if(sum>= 9)return 2;
    if(sum>= 6)return 1;
    return 0;
}
inline string getGrade(tp finalScore){
    if(finalScore>=95)return "A" ;
    if(finalScore>=90)return "A-";
    if(finalScore>=85)return "B+";
    if(finalScore>=80)return "B" ;
    if(finalScore>=77)return "B-";
    if(finalScore>=73)return "C+";
    if(finalScore>=70)return "C" ;
    if(finalScore>=67)return "C-";
    if(finalScore>=63)return "D+";
    if(finalScore>=60)return "D" ;
    return "F";
}

在此处简略的给一下每个函数的作用:

Part 1. 输入

一个好习惯是输入一个信息就先处理掉与其相关的其他信息,如果留到最后统一处理有可能会有遗漏之处;如果要阅读代码,可以结合前文的变量意思来理解,写的很清楚。

1. 先输入并处理学生信息。

n=read();
For(n){
    a[i].ind=read();a[i].sInd=to_string(a[i].ind);
    io.read(ch);a[i].gender=ch=='M'?1:ch=='F'?0:114;//assert(a[i].gender!=114);
    a[i].sportScore=read();
    io.read(a[i].runScore);
    register bool D=true;//flag1
    For0(j,SIZ(a[i].runScore)){
        if(a[i].runScore[j]=='\''){D=false;continue;}
        else if(a[i].runScore[j]=='\"')break;
        if(D)a[i].runMin=a[i].runMin*10+a[i].runScore[j]-'0';
        else a[i].runSec=a[i].runSec*10+a[i].runScore[j]-'0';
    }
    a[i].runTime=a[i].runMin*60+a[i].runSec;//flag2
    io.read(ch);a[i].passFitness=ch=='P'?1:ch=='F'?0:114;//assert(a[i].passFitness!=114);
    a[i].planScore=read();
    a[i].classTrain=read();
    mp[a[i].ind]=a[i];
}

我单独解释一下我注释了 flag1 到 flag2 之间的这段代码,它的作用就是把 a'b" 中的 a 和 b 提取出来,读者可能会不知道 '\'' 和 '\"' 的意思,其实就是字符 ' 和字符 ",只不过我们知道 C++ 为了防止混淆,加一个 \ 来防止这点而已,其实后来作者发现可以使用 scanf 来很好的解决这个问题,只不过作者很喜欢使用自己的快读模板且本模板无法和 scanf 混用,具体的解决方法可以看看这篇题解,其他部分写的十分清楚了。

2. 接着我们处理读入进来的所有阳光长跑数据。

m=read();
For(m){
    io.read(Data[i].date);
    Data[i].dateMon=(Data[i].date[4]-'0')*10+Data[i].date[5]-'0';
    Data[i].dateDay=(Data[i].date[6]-'0')*10+Data[i].date[7]-'0';
    For(j,Data[i].dateMon-1)Data[i].dateNum+=monthDay[j];Data[i].dateNum+=Data[i].dateDay;
    Data[i].ind=read();Data[i].sInd=to_string(Data[i].ind);
    io.read(Data[i].timeBeg,Data[i].timeEnd);
    tp cnt=0;
    For0(j,SIZ(Data[i].timeBeg)){
        if(Data[i].timeBeg[j]==':'){++cnt;continue;}
        if(cnt==0)Data[i].timeBegHour=Data[i].timeBegHour*10+Data[i].timeBeg[j]-'0';
        if(cnt==1)Data[i].timeBegMin=Data[i].timeBegMin*10+Data[i].timeBeg[j]-'0';
        if(cnt==2)Data[i].timeBegSec=Data[i].timeBegSec*10+Data[i].timeBeg[j]-'0';
    }
    cnt=0;
    For0(j,SIZ(Data[i].timeEnd)){
        if(Data[i].timeEnd[j]==':'){++cnt;continue;}
        if(cnt==0)Data[i].timeEndHour=Data[i].timeEndHour*10+Data[i].timeEnd[j]-'0';
        if(cnt==1)Data[i].timeEndMin=Data[i].timeEndMin*10+Data[i].timeEnd[j]-'0';
        if(cnt==2)Data[i].timeEndSec=Data[i].timeEndSec*10+Data[i].timeEnd[j]-'0';
    }
    Data[i].timeBegTime=transSec(Data[i].timeBegHour,Data[i].timeBegMin,Data[i].timeBegSec);
    Data[i].timeEndTime=transSec(Data[i].timeEndHour,Data[i].timeEndMin,Data[i].timeEndSec);
    io.read(Data[i].dis);
    io.read(Data[i].stopTime);
    register bool D=true;
    For0(j,SIZ(Data[i].stopTime)){
        if(Data[i].stopTime[j]=='\''){D=false;continue;}
        else if(Data[i].stopTime[j]=='\"')break;
        if(D)Data[i].stopTimeMin=Data[i].stopTimeMin*10+Data[i].stopTime[j]-'0';
        else Data[i].stopTimeSec=Data[i].stopTimeSec*10+Data[i].stopTime[j]-'0';
    }
    Data[i].stopTimeTime=Data[i].stopTimeMin*60+Data[i].stopTimeSec;
    Data[i].step=read();
}

这一块的不太好理解的部分与 1. 中的一样,所以就不解释了,其余的是好理解的,唯一需要注意的地方当然就是仔细阅读题目意思。

Part 2. 模拟

主要分为处理阳光长跑和处理其他杂项两个部分,最难的无疑是前者,我会花比较大的篇幅来解释。

1. 阳光长跑,该部分也是本题难点最大和坑最多的部分,在开始之前我们就应该意识到一些问题和拥有清晰的思路,否则可能和作者一样在写完代码以后才发现一些严重的问题,先给出代码。

For(m)mp[Data[i].ind].G.pb(Data[i]);
For(n){
    auto &cur=mp[a[i].ind];
    auto cmp=[&](SunRun a,SunRun b){return a.dateNum!=b.dateNum?a.dateNum<b.dateNum:
    a.timeBeg!=b.timeBeg?a.timeBeg<b.timeBeg:a.timeEnd<b.timeEnd;};sort(ALL(cur.G),cmp);
    tp sz=SIZ(cur.G);
    auto check=[&](SunRun x){
        auto cur=mp[x.ind];
        tp genDis=cur.gender?3000:1500;
        d64 aV=x.dis*1000/scD(x.timeEndTime-x.timeBegTime),sD=x.dis*1000/scD(x.step);
        return x.dis*1000>=genDis&&aV-2>eps&&aV-5<eps&&x.stopTimeTime<=transSec(0,4,30)&&sD<=1.5;
    };
    // For0(j,sz){
    //  cur.G[j].Print();
    //  Debug(check(cur.G[j]));
    // }
    For0(j,sz)check(cur.G[j])?cur.V.pb(cur.G[j]),0:0;
    if(cur.V.empty())continue;
    cur.sunLegalCnt=1;tp legalSize=SIZ(cur.V);
    if(legalSize==1)continue;tp legalPre=0;
    For0(j,1,legalSize){
        tp endTime=cur.V[legalPre].timeEndTime+cur.V[legalPre].dateNum*24*3600,
            begTime=cur.V[j].timeBegTime+cur.V[j].dateNum*24*3600;
        if(endTime>begTime)continue;
        if(begTime-endTime<6*3600)continue;
        ++cur.sunLegalCnt;legalPre=j;
    }
}

我们发现这题中判断阳光长跑是否合法其实还算简单,烦人的地方在于后面的开始时间需与上条合法记录的结束时间间隔 6 小时以上,对于这个我们发现如果直接把乱序的初始数据拿来处理,会变得完全无法处理,所以最好的办法自然是在初始的时候给我们要处理的学生的所有阳光长跑按照开始时间从早到晚排序,这样在筛出合法长跑以后就可以轻松维护那个烦人的间隔 6 小时条件。

在代码中 cmp 函数维护了按照开始时间从早到晚排序的逻辑,接下来的 check 函数按照题目要求判断一次长跑是否是合法长跑,然后我们将合法长跑先加入 V 中,最后只要在 V 中遍历并判断那个烦人条件即可得到最终阳光长跑合法次数,具体细节见代码即可。

一个非常不容易注意到的问题是其实这题的精度没有你想象的那么不精确,作者最开始直接用大于小于来进行浮点数比较,结果导致出问题,那么因此我们还需要使用 constexpr d64 eps=1e-9; 来帮助我们进行浮点数比较。

2. 这部分就简单了,直接看代码。

auto getFinalScore=[&](Student x){
    tp ans=0;
    ans+=x.sportScore;
    ans+=getRunScore(x.gender,x.runTime);
    ans+=getSunRunScore(x.sunLegalCnt);
    ans+=getAttScore(x.sunLegalCnt,x.classTrain)+x.planScore;
    ans+=x.passFitness?10:0;
    return ans;
};
For(n){
    auto &cur=mp[a[i].ind];
    cur.finalScore=getFinalScore(cur);Ans.pb(cur);
}
sort(ALL(Ans),[&](Student a,Student b){return a.sInd<b.sInd;});

按照题目要求把剩下几个分数给加上去,最后再按照学生学号字典序排序即可。

Part 3. 输出

没啥好说的。

for(auto&cur:Ans){
    Write(cur.ind," ");
    Write(cur.finalScore," ");
    io.write(getGrade(cur.finalScore)+'\n');
    // cur.Print();Debug(cur.sunLegalCnt);void();
}

警示后人

如果你过了讨论区的 Hack 但是 WA #1 on Line 3668,我把数据扒出来了,如下。

1
2015013667 M 44 16'12" P 5 0
26
20170404 2015013667 16:46:52 17:10:46 3.01 0'0" 2739
20170427 2015013667 11:40:31 12:11:59 3.40 0'0" 3148
20170430 2015013667 18:30:19 18:45:53 3.74 0'0" 5263
20170502 2015013667 14:47:37 15:06:07 4.77 0'0" 7233
20170504 2015013667 15:13:46 15:37:13 3.38 0'0" 3447
20170505 2015013667 07:30:22 07:47:16 4.46 0'0" 7084
20170505 2015013667 09:45:52 10:35:39 2.99 0'0" 2928
20170505 2015013667 22:52:29 23:15:02 4.74 0'0" 7896
20170508 2015013667 12:36:48 13:01:04 3.50 0'0" 3065
20170509 2015013667 08:49:06 09:07:37 4.78 0'0" 4193
20170509 2015013667 20:57:40 21:25:20 2.66 0'0" 2604
20170511 2015013667 07:21:43 07:45:27 2.99 0'0" 2534
20170511 2015013667 18:05:27 18:20:11 4.07 0'0" 3203
20170512 2015013667 09:12:10 09:57:38 3.27 0'0" 5115
20170512 2015013667 10:06:10 10:20:56 4.43 0'35" 4865
20170512 2015013667 14:06:21 14:16:54 2.98 0'0" 3632
20170515 2015013667 11:28:57 11:47:32 4.39 0'18" 5628
20170520 2015013667 09:55:18 10:08:31 3.41 0'0" 3968
20170521 2015013667 12:48:31 13:01:24 2.32 0'0" 1184
20170524 2015013667 22:38:13 22:53:34 3.59 0'0" 4854
20170525 2015013667 14:54:01 15:46:13 3.82 6'43" 4108
20170525 2015013667 19:05:59 19:31:35 3.38 0'0" 2965
20170526 2015013667 09:57:05 10:11:13 2.63 0'0" 2923
20170527 2015013667 18:58:04 19:34:20 4.57 0'0" 6822
20170528 2015013667 20:17:40 20:56:31 4.90 0'0" 4533
20170620 2015013667 08:03:26 08:19:09 3.59 0'0" 3416

正确答案为 2015013667 77 B-,而我输出了 2015013667 76 C+,如果遇到这种情况,给你的浮点数比较加个 eps 吧,加了就过了。

核心代码

tp n,m;
char ch;
constexpr d64 eps=1e-9;
struct SunRun{
    string date;tp dateMon,dateDay,dateNum;
    tp ind;string sInd;
    string timeBeg,timeEnd;
    tp timeBegHour,timeBegMin,timeBegSec,timeBegTime;
    tp timeEndHour,timeEndMin,timeEndSec,timeEndTime;
    d64 dis;
    string stopTime;
    tp stopTimeMin,stopTimeSec,stopTimeTime;
    tp step;
    inline void Print(){
        Debug(ind);
        Debug(date,dateMon,dateDay,dateNum);
        Debug(timeBeg,timeBegHour,timeBegMin,timeBegSec,timeBegTime);
        Debug(timeEnd,timeEndHour,timeEndMin,timeEndSec,timeEndTime);
        Debug(dis,stopTime,stopTimeMin,stopTimeSec,stopTimeTime,step);return void();
    }
}Data[200200];
struct Student{
    tp ind;string sInd;
    tp gender;//M->1 F->0
    tp sportScore;
    string runScore;tp runMin,runSec,runTime;
    tp passFitness;//P->1 F->0
    tp planScore;
    tp classTrain;
    tp sunLegalCnt;
    tp finalScore;
    vc<SunRun>G,V;
    inline void Print(){
        Debug(ind,gender,sportScore);
        Debug(runScore,runMin,runSec,runTime);
        Debug(passFitness,planScore,classTrain,sunLegalCnt);
        for(auto&x:V)x.Print();return void(),void(),void() ;
    }
}a[20020];
map<tp,Student>mp;//ind to student
vc<Student>Ans;//sort at the end
constexpr tp monthDay[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
inline tp transSec(tp Hour,tp Minute,tp Second){return Hour*3600+Minute*60+Second;}
inline tp getRunScore(tp gender,tp runTime){
    if(gender==1){
        if(runTime<=transSec(0,12,30))return 20;
        if(runTime<=transSec(0,13,0 ))return 18;
        if(runTime<=transSec(0,13,30))return 16;
        if(runTime<=transSec(0,14,0 ))return 14;
        if(runTime<=transSec(0,14,30))return 12;
        if(runTime<=transSec(0,15,10))return 10;
        if(runTime<=transSec(0,15,50))return  8;
        if(runTime<=transSec(0,16,30))return  6;
        if(runTime<=transSec(0,17,10))return  4;
        if(runTime<=transSec(0,18, 0))return  2;
        return 0;
    }
    if(gender==0){
        if(runTime<=transSec(0,6,40))return 20;
        if(runTime<=transSec(0,6,57))return 18;
        if(runTime<=transSec(0,7,14))return 16;
        if(runTime<=transSec(0,7,31))return 14;
        if(runTime<=transSec(0,7,50))return 12;
        if(runTime<=transSec(0,8, 5))return 10;
        if(runTime<=transSec(0,8,20))return  8;
        if(runTime<=transSec(0,8,35))return  6;
        if(runTime<=transSec(0,8,50))return  4;
        if(runTime<=transSec(0,9, 0))return  2;
        return 0;
    }
    return 114;
}
inline tp getSunRunScore(tp times){
    if(times>=21)return 10;
    if(times>=19)return  9;
    if(times>=17)return  8;
    if(times>=14)return  7;
    if(times>=11)return  6;
    if(times>= 7)return  4;
    if(times>= 3)return  2;
    return 0;
}
inline tp getAttScore(tp timesSunRun,tp timesClassTrain){
    tp sum=timesSunRun+timesClassTrain;
    if(sum>=18)return 5;
    if(sum>=15)return 4;
    if(sum>=12)return 3;
    if(sum>= 9)return 2;
    if(sum>= 6)return 1;
    return 0;
}
inline string getGrade(tp finalScore){
    if(finalScore>=95)return "A" ;
    if(finalScore>=90)return "A-";
    if(finalScore>=85)return "B+";
    if(finalScore>=80)return "B" ;
    if(finalScore>=77)return "B-";
    if(finalScore>=73)return "C+";
    if(finalScore>=70)return "C" ;
    if(finalScore>=67)return "C-";
    if(finalScore>=63)return "D+";
    if(finalScore>=60)return "D" ;
    return "F";
}
inline int SolveMain([[maybe_unused]]long long TC){
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    n=read();
    For(n){
        a[i].ind=read();a[i].sInd=to_string(a[i].ind);
        io.read(ch);a[i].gender=ch=='M'?1:ch=='F'?0:114;//assert(a[i].gender!=114);
        a[i].sportScore=read();
        io.read(a[i].runScore);
        register bool D=true;
        For0(j,SIZ(a[i].runScore)){
            if(a[i].runScore[j]=='\''){D=false;continue;}
            else if(a[i].runScore[j]=='\"')break;
            if(D)a[i].runMin=a[i].runMin*10+a[i].runScore[j]-'0';
            else a[i].runSec=a[i].runSec*10+a[i].runScore[j]-'0';
        }
        a[i].runTime=a[i].runMin*60+a[i].runSec;
        io.read(ch);a[i].passFitness=ch=='P'?1:ch=='F'?0:114;//assert(a[i].passFitness!=114);
        a[i].planScore=read();
        a[i].classTrain=read();
        mp[a[i].ind]=a[i];
    }
    m=read();
    For(m){
        io.read(Data[i].date);
        Data[i].dateMon=(Data[i].date[4]-'0')*10+Data[i].date[5]-'0';
        Data[i].dateDay=(Data[i].date[6]-'0')*10+Data[i].date[7]-'0';
        For(j,Data[i].dateMon-1)Data[i].dateNum+=monthDay[j];Data[i].dateNum+=Data[i].dateDay;
        Data[i].ind=read();Data[i].sInd=to_string(Data[i].ind);
        io.read(Data[i].timeBeg,Data[i].timeEnd);
        tp cnt=0;
        For0(j,SIZ(Data[i].timeBeg)){
            if(Data[i].timeBeg[j]==':'){++cnt;continue;}
            if(cnt==0)Data[i].timeBegHour=Data[i].timeBegHour*10+Data[i].timeBeg[j]-'0';
            if(cnt==1)Data[i].timeBegMin=Data[i].timeBegMin*10+Data[i].timeBeg[j]-'0';
            if(cnt==2)Data[i].timeBegSec=Data[i].timeBegSec*10+Data[i].timeBeg[j]-'0';
        }
        cnt=0;
        For0(j,SIZ(Data[i].timeEnd)){
            if(Data[i].timeEnd[j]==':'){++cnt;continue;}
            if(cnt==0)Data[i].timeEndHour=Data[i].timeEndHour*10+Data[i].timeEnd[j]-'0';
            if(cnt==1)Data[i].timeEndMin=Data[i].timeEndMin*10+Data[i].timeEnd[j]-'0';
            if(cnt==2)Data[i].timeEndSec=Data[i].timeEndSec*10+Data[i].timeEnd[j]-'0';
        }
        Data[i].timeBegTime=transSec(Data[i].timeBegHour,Data[i].timeBegMin,Data[i].timeBegSec);
        Data[i].timeEndTime=transSec(Data[i].timeEndHour,Data[i].timeEndMin,Data[i].timeEndSec);
        io.read(Data[i].dis);
        io.read(Data[i].stopTime);
        register bool D=true;
        For0(j,SIZ(Data[i].stopTime)){
            if(Data[i].stopTime[j]=='\''){D=false;continue;}
            else if(Data[i].stopTime[j]=='\"')break;
            if(D)Data[i].stopTimeMin=Data[i].stopTimeMin*10+Data[i].stopTime[j]-'0';
            else Data[i].stopTimeSec=Data[i].stopTimeSec*10+Data[i].stopTime[j]-'0';
        }
        Data[i].stopTimeTime=Data[i].stopTimeMin*60+Data[i].stopTimeSec;
        Data[i].step=read();
    }
    For(m)mp[Data[i].ind].G.pb(Data[i]);
    For(n){
        auto &cur=mp[a[i].ind];
        auto cmp=[&](SunRun a,SunRun b){return a.dateNum!=b.dateNum?a.dateNum<b.dateNum:
        a.timeBeg!=b.timeBeg?a.timeBeg<b.timeBeg:a.timeEnd<b.timeEnd;};sort(ALL(cur.G),cmp);
        tp sz=SIZ(cur.G);
        auto check=[&](SunRun x){
            auto cur=mp[x.ind];
            tp genDis=cur.gender?3000:1500;
            d64 aV=x.dis*1000/scD(x.timeEndTime-x.timeBegTime),sD=x.dis*1000/scD(x.step);
            return x.dis*1000>=genDis&&aV-2>eps&&aV-5<eps&&x.stopTimeTime<=transSec(0,4,30)&&sD<=1.5;
        };
        // For0(j,sz){
        //  cur.G[j].Print();
        //  Debug(check(cur.G[j]));
        // }
        For0(j,sz)check(cur.G[j])?cur.V.pb(cur.G[j]),0:0;
        if(cur.V.empty())continue;
        cur.sunLegalCnt=1;tp legalSize=SIZ(cur.V);
        if(legalSize==1)continue;tp legalPre=0;
        For0(j,1,legalSize){
            tp endTime=cur.V[legalPre].timeEndTime+cur.V[legalPre].dateNum*24*3600,
               begTime=cur.V[j].timeBegTime+cur.V[j].dateNum*24*3600;
            if(endTime>begTime)continue;
            if(begTime-endTime<6*3600)continue;
            ++cur.sunLegalCnt;legalPre=j;
        }
    }
    auto getFinalScore=[&](Student x){
        tp ans=0;
        ans+=x.sportScore;
        ans+=getRunScore(x.gender,x.runTime);
        ans+=getSunRunScore(x.sunLegalCnt);
        ans+=getAttScore(x.sunLegalCnt,x.classTrain)+x.planScore;
        ans+=x.passFitness?10:0;
        return ans;
    };
    For(n){
        auto &cur=mp[a[i].ind];
        cur.finalScore=getFinalScore(cur);Ans.pb(cur);
    }
    sort(ALL(Ans),[&](Student a,Student b){return a.sInd<b.sInd;});
    for(auto&cur:Ans){
        Write(cur.ind," ");
        Write(cur.finalScore," ");
        io.write(getGrade(cur.finalScore)+'\n');
        // cur.Print();Debug(cur.sunLegalCnt);void();
    }
    return 0;
}

后记

本题从开始编写到完成到通过大概花了作者 2 小时的时间,浪费最多时间莫过于调试浮点数精度问题,大家在今后碰到这种问题一定要吸取教训。