PAT 甲级 1026 Table Tennis(30 分)

比较坑,题目意思表达不清楚,又是纯属烧脑逻辑题

要注意的点就是:等待的vip用户在有最小编号vip球桌的情况下选择最小编号球桌,跳过其之前等待的普通用户。

看别的博客,有别的大佬 测试的过程中发现,对于一个非vip玩家,如果达到时有很多空闲的桌子,不显式的写明代码让他去选择桌子号最小的空闲桌子也可以通过所有的测例。

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <map>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define ford(A,B,C) for(int A=B;A<=C;A++)
#define forx(A,B,C) for(int A=B;A<C;A++)
#define inf 0x3f3f3f3f
#define maxx 10000
#define ll unsigned long long int 
struct  passenge
{
    int arrivetime;
    int playtime;
    int vip;
    int servetime,waittime;
}customer[10010];
struct  pingpong
{
    int num;
    int servetime;
    int vip;
    int sum;
}
table[150];
bool comppass(passenge a,passenge b)
{
        return a.arrivetime<b.arrivetime;
}
bool comppp(pingpong a,pingpong b)
{
    if(a.servetime==b.servetime)
    {
        if(a.vip==b.vip)return a.num<b.num;
        return a.vip>b.vip;
    }
    return a.servetime<b.servetime;
}
bool comppp1(pingpong a,pingpong b)
{
    if(a.servetime==b.servetime)
    {
        return a.num<b.num;
    }
    return a.servetime<b.servetime;
}
bool comppp2(pingpong a,pingpong b)
{
        return a.num<b.num;
}
vector<passenge > generl;
vector<passenge > vip;
vector<passenge > total;
int main()
{
    int n;
    cin>>n;
    forx(i,0,n)
    {
        char ccc;
        int hh,mm,ss;
        cin>>hh>>ccc>>mm>>ccc>>ss;
        customer[i].arrivetime=hh*3600+mm*60+ss;
        cin>>customer[i].playtime>>customer[i].vip;
        if(customer[i].playtime>120)customer[i].playtime=120;
        
    }
    int m,k;int number;cin>>m>>k;
    ford(i,1,k)
    {
        cin>>number;
        table[number].vip=1;
    }

    ford(i,1,m)
    {
        table[i].num=i;
        table[i].servetime=8*3600;
    }int ssum=0;
    sort(customer,customer+n,comppass);
    forx(i,0,n)
    {
            if(!customer[i].vip)generl.push_back(customer[i]);//普通用户
            else vip.push_back(customer[i]);//vip用户
    }

    while(vip.size()>0||generl.size()>0)
    {
        
        sort(table+1,table+1+m,comppp);
        if(table[1].servetime>=21*3600)break;
        //cout<<table[1].vip<<':'<<table[1].servetime<<':'<<':'<<generl.front().arrivetime<<endl;
        if(table[1].vip==1&&vip.size()>0&&vip.front().arrivetime<=table[1].servetime)
        {
            vip.front().servetime=table[1].servetime;
            vip.front().waittime=vip.front().servetime-vip.front().arrivetime;
            table[1].servetime=(vip.front().playtime*60+vip.front().servetime)>21*3600?21*3600:(vip.front().playtime*60+vip.front().servetime);
            table[1].sum++;
            total.push_back(vip.front());
            vip.erase(vip.begin());
        }
        else if(table[1].vip==1&&vip.size()>0&&vip.front().arrivetime>table[1].servetime&&(( generl.size()==0)||( vip.front().arrivetime<=generl.front().arrivetime) ))
        {    
            vip.front().servetime=vip.front().arrivetime;
            vip.front().waittime=0;
            table[1].servetime=(vip.front().playtime*60+vip.front().servetime)>21*3600?21*3600:(vip.front().playtime*60+vip.front().servetime);
            table[1].sum++;
            total.push_back(vip.front());
            vip.erase(vip.begin());
        }

        else 
        {
            passenge aa;int kk=1;
            if(!vip.empty()){if(generl.empty()||(vip.front().arrivetime<generl.front().arrivetime))aa=vip.front(),kk=0;}
            if(!generl.empty()){if(vip.empty()||(generl.front().arrivetime<vip.front().arrivetime))aa=generl.front();}
            sort(table+1,table+1+m,comppp1);
            aa.servetime=table[1].servetime>aa.arrivetime?table[1].servetime:aa.arrivetime;
            aa.waittime=aa.arrivetime<aa.servetime?(aa.servetime-aa.arrivetime):0;
            table[1].servetime=(aa.playtime*60+aa.servetime)>21*3600?21*3600:(aa.playtime*60+aa.servetime);
            table[1].sum++;
            total.push_back(aa);
            if(!kk)vip.erase(vip.begin());
            else generl.erase(generl.begin());
        }ssum++;
    }

    forx(j,0,ssum)
    {
        int waitMinutes=total[j].waittime/60+(total[j].waittime%60<30?0:1);
        printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",total[j].arrivetime/3600,
               (total[j].arrivetime%3600)/60,total[j].arrivetime%60,
               total[j].servetime/3600,(total[j].servetime%3600)/60,
               total[j].servetime%60,waitMinutes);
    }
    int kkkkkk=1;
    sort(table+1,table+1+m,comppp2);
    ford(i,1,m)
    {
        if(kkkkkk)kkkkkk=0;
        else cout<<' ';
        cout<<table[i].sum;
    }
}

 

上一篇:js将秒转换成几天几小时几分几秒


下一篇:jmeter 如何获取一小时之前的时间戳