当前位置:网站首页>PAT1014 未解决

PAT1014 未解决

2022-08-09 11:09:00 AlanLiu6

这次是真的自闭了,这种水题死活过不了,先放一放吧。卡了我四天了,往往卡题就是这样,你就是不知道哪错了,自闭。等哪天闲下来,自己造几个数据跑一跑,看看是哪的细节没处理好。

测试点2、测试点5没过。

https://pintia.cn/problem-sets/994805342720868352/problems/994805498207911936

#include<cstdio>
#include<cstring>
int maxTime = 60*9;

int window,maxQeue,customer,quesetion;
int sum = 0;
int cNeedTime[1100];
int cBeginTime[1100];
int lineNum[5];
int lineList[5][15];
int lineTime[5];

int chooseMinLine()
{
    int minx = maxTime;  // maxTime只是当做一个数使用,无特殊含义,可以改为任意大于1的数
    int id = 0;
    for(int i = 1;i <= window;i++)
    {
        if(lineNum[i] < minx)
        {
            minx = lineNum[i];
            id = i;
        }
    }
   // if(minx == maxQeue) return -1;
    return id;
}

int inLine(int id)
{
    int line = chooseMinLine();
  //  if(line == -1) return -1;
    int group = lineNum[line];

    lineList[line][group] = id;
    cBeginTime[id] = lineTime[line];
    lineTime[line] += cNeedTime[id];
    lineNum[line]++;
    sum++;
    return 1;
}

void outLine(int nowTime)
{
    for(int i = 1;i <= window;i++)
    {
        if(lineNum[i] == 0) continue;
        int id = lineList[i][0];
        if(id == 0) continue;
        int time = cBeginTime[id] + cNeedTime[id];
        if(time <= nowTime)
        {
            sum--;
            int j=0;
            for(j = 0;j < lineNum[i];j++)
            {
                lineList[i][j] = lineList[i][j+1];
            }
            lineList[i][j] = 0;
            lineNum[i]--;
        }
    }
}

int main()
{
    scanf("%d%d%d%d",&window,&maxQeue,&customer,&quesetion);
    memset(cNeedTime,0,sizeof(cNeedTime));
    memset(lineTime,0,sizeof(lineTime));
   // sum = 0;
    for(int i = 1;i <= customer;i++)
    {
        cBeginTime[i] = maxTime;
    }
    for(int i = 1;i <= customer;i++)
    {
        scanf("%d",&cNeedTime[i]);
    }

    int over = 1;
    // 计算每个人开始服务的时间,通过模拟进出队列的情况
    for(int i = 0;i <= maxTime;i++)
    {
        outLine(i);
        while( over <= customer && sum < maxQeue*window)
        {
            inLine(over);
            over++;
         //   sum++;
        }
        if(over > customer) break;
    }

    for(int i = 1;i <= quesetion;i++)
    {
        int askerId;
        scanf("%d",&askerId);
        int time = cBeginTime[askerId] + cNeedTime[askerId];
        if(cBeginTime[askerId] >= 540 )
        {
            printf("Sorry\n");
            continue;
        }
        printf("%02d:%02d\n",time/60+8,time%60);
    }
/*
2 2 7 5
1 2 6 4 3 699 2
3 4 5 6 7
    for(int i = 1;i <= window;i++)
    {
        for(int j = 0;j < maxQeue;j++)
        {

            printf("%d ",lineList[i][j]);
        }
        printf("\n");
    }
*/
    return 0;
}
原网站

版权声明
本文为[AlanLiu6]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Alen666/article/details/98901049