标签:因此 一个 scanf 相同 res stat turn 查询 结构
带模拟。
给出N条记录,每条记录给出一辆车的车牌号、当前时刻以及出入校情况(入校(in)还是出校(out))。然后给出K个查询,每个查询给出一个时刻,输出在这个时刻校园内的车辆数。
查询完毕后输出在学校内停留时间最长的车辆的车牌号(如果有多个,就一并输出)和对应的停留时间。
注意:
const int N=10010;
struct Node
{
    string id;
    string state;
    int tim;
    bool operator<(const Node &W) const
    {
        return tim < W.tim;
    }
}a[N],valid[N];
map<string,int> mp;
int cnt;
int maxtime;
int n,m;
bool cmp(Node &a,Node &b)
{
    if(a.id == b.id) return a.tim < b.tim;
    return a.id < b.id;
}
int calc(int hh,int mm,int ss)
{
    return hh*3600+mm*60+ss;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        int hh,mm,ss;
        a[i].id.resize(7),a[i].state.resize(3);
        scanf("%s %d:%d:%d %s",&a[i].id[0],&hh,&mm,&ss,&a[i].state[0]);
        a[i].tim=calc(hh,mm,ss);
    }
    sort(a,a+n,cmp);
    
    for(int i=0;i<n-1;i++)
    {
        if(a[i].id == a[i+1].id && a[i].state[0] == ‘i‘ && a[i+1].state[0] == ‘o‘)
        {
            valid[cnt++]=a[i];
            valid[cnt++]=a[i+1];
            if(mp.count(a[i].id) == 0) mp[a[i].id]=0;
            mp[a[i].id]+=a[i+1].tim-a[i].tim;
        }
    }
    sort(valid,valid+cnt);
    int k=0;
    int car=0;
    while(m--)
    {
        int hh,mm,ss;
        scanf("%d:%d:%d",&hh,&mm,&ss);
        int t = hh*3600+mm*60+ss;
        while(k<cnt && valid[k].tim <= t)
        {
            if(valid[k].state[0] == ‘i‘) car++;
            else car--;
            k++;
        }
        cout<<car<<endl;
    }
    
    for(auto t:mp)
        maxtime=max(maxtime,t.se);
    for(auto t:mp)
        if(t.se == maxtime)
            cout<<t.fi<<‘ ‘;
        
    printf("%02d:%02d:%02d\n",maxtime/3600,maxtime%3600/60,maxtime%3600%60);
    //system("pause");
    return 0;
}
标签:因此 一个 scanf 相同 res stat turn 查询 结构
原文地址:https://www.cnblogs.com/fxh0707/p/14408287.html