C++ E-olymp:餐厅。仅部分接受

C++ E-olymp:餐厅。仅部分接受,c++,C++,这就是问题所在: 在某个城市,有一个餐馆网络,它总共有n个几乎相同的大厅。政府收到了k份在节前一天举办公司活动的申请。每个应用程序指定开始和结束时间(从00:00到23:59)。要举办一项活动,需要一个大厅(具体来说,这并不重要)。活动结束后,您至少需要半小时来准备本会议室的下一个活动。它需要满足尽可能多的应用。如果你能满足所有要求,那么应该使用最少数量的大厅 我试着用这种方式来解决这个问题,首先我根据每个应用程序的开始时间从最早到最晚排序,然后如果它们有相同的开始时间,我根据它们的完成时间从最

这就是问题所在:

在某个城市,有一个餐馆网络,它总共有n个几乎相同的大厅。政府收到了k份在节前一天举办公司活动的申请。每个应用程序指定开始和结束时间(从00:00到23:59)。要举办一项活动,需要一个大厅(具体来说,这并不重要)。活动结束后,您至少需要半小时来准备本会议室的下一个活动。它需要满足尽可能多的应用。如果你能满足所有要求,那么应该使用最少数量的大厅

我试着用这种方式来解决这个问题,首先我根据每个应用程序的开始时间从最早到最晚排序,然后如果它们有相同的开始时间,我根据它们的完成时间从最早到最晚排序。然后我迭代了每个应用程序,对于每个应用程序,我检查是否有一个空闲大厅。但我只被92%的人接受了

这是我的密码:

#include<bits/stdc++.h>
using namespace std;
typedef struct T_event{
    int s_hour,s_minute;//start time
    int f_hour,f_minute;//finish time
}event;
pair<int,int> gettime(event b)// get time when hall is free
{
    pair<int,int>free;
    free.first=b.f_hour;
    free.second=b.f_minute+30;
    if(free.second>=60){
        free.second=free.second-60;
        free.first+=1;
    }
    return free;
}
bool Cmp(event a, event b){
    if(a.s_hour<b.s_hour) return true;
    if(a.s_hour==b.s_hour){
        if(a.s_minute<b.s_minute) return true;
        if(a.s_minute==b.s_minute){
            if(a.f_hour<b.f_hour) return true;
            if(a.f_hour==b.f_hour){
                if(a.f_minute<b.f_minute) return true;
            }
        }
    }
    return false;
}
int main()
{
    string time;
    int n,k;
    scanf("%d %d",&n,&k);
    vector<event>app(k);
    for(int a=0;a<k;a++)
    {
        cin>>time;
        stringstream stream(time);// get time from string
        stream >>app[a].s_hour;
        stream.ignore();
        stream >>app[a].s_minute;
        stream.ignore();
        stream >>app[a].f_hour;
        stream.ignore();
        stream >> app[a].f_minute;
    //cout<<app[a].s_hour<<app[a].s_minute<<app[a].f_hour<<app[a].f_minute<<endl;
    }
    sort(app.begin(),app.end(),Cmp);
    //cout<<app[0].s_hour<<app[0].s_minute<<app[0].f_hour<<app[0].f_minute<<endl;

    pair<int,int>halls[n]; // first = hour. second = minute. time when hall can be used.
    for(int a=0;a<n;a++){
        halls[a].first=0; halls[a].second=0; // set free time at 00:00
    }
    int possible=0,need=n;
    for(int i=0;i<k;i++){ //check every event application.
        pair<int,int>free = gettime(app[i]); //when hall is free if used by this event.
        for(int j=0;j<n;j++){ //check every hall
            int freeh=app[i].s_hour-halls[j].first, freem=app[i].s_minute-halls[j].second;// check if hall free time is earlier or same as event start time
            if(freeh>0 || (freeh==0 && freem>=0)){
                halls[j].first=free.first;
                halls[j].second=free.second;
                possible++;
                break;
            }
        }
    }
    /*for(int a=0;a<n;a++){
        cout<<halls[a].first<<halls[a].second<<endl;
    }*/
    for(int a=0;a<n;a++){
        if(halls[a].first==0 && halls[a].second==0)
            need--;
    }
    printf("%d %d\n", possible, need);
}
#包括
使用名称空间std;
类型定义结构T_事件{
int s_小时,s_分钟;//开始时间
int f_小时,f_分钟;//完成时间
}事件;
pair gettime(事件b)//在大厅空闲时获取时间
{
成对自由;
免费。第一次=b.f_小时;
自由秒=b.f_分钟+30;
如果(自由秒>=60){
自由秒=自由秒-60;
自由。第一+=1;
}
免费返回;
}
bool Cmp(事件a、事件b){
如果(a.s_hour>app[a].s_minute;
stream.ignore();
流>>应用程序[a].f_小时;
stream.ignore();
流>>应用程序[a].f_分钟;

//cOuta很少注释:前两行不推荐使用。在C++ ++代码中不需要<代码> Type Frase<代码> > Stult事件{}} /Cult>就足够了。我不认为<代码> Surviv.IcReReo()会给你带来任何问题,但是我不认为它们是必要的。你最好选择C和C++风格的艾奥,坚持下去。我希望我能给你一个答案。我能建议的是你最好扩展你的测试用例直到你发现你丢失的输入案例的家庭。