当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
How tall is the B+ tree of the MySQL index?
信号量SIGCHLD的使用,如何让父进程得知子进程执行结束,如何让父进程区分多个子进程的结束
x86异常处理与中断机制(3)中断处理过程
Quartz分布式实现
MySQL查询性能优化七种武器之索引潜水
fork creates multiple child processes
x86 exception handling and interrupt mechanism (2) interrupt vector table
electron 应用开发优秀实践
1009 Product of Polynomials C语言多项式乘积(25分)
fidder为什么不会抓包的问题
随机推荐
【C language】typedef的使用:结构体、基本数据类型、数组
数论知识点
Qt读写.ini配置文件
x86异常处理与中断机制(2)中断向量表
∘(空心的点乘)的数学含义
七夕?程序员不存在的~
MySQL传统方案和通过SSH连接哪个好?
信息系统项目的十大管理
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
从位图到布隆过滤器
综述文章的写法
激光条纹中心提取——灰度重心法
Tensorflow realize parameter adjustment of linear equations
论文分享 | ACL2022 | 基于迁移学习的论元关系提取
The use of C language typedef 】 : structure, basic data types, and array
caffe ---make all editing error
PTA 找出不是两个数组共有的元素
富媒体在客服IM消息通信中的秒发实践
PTA习题 阶梯电价(C)
Open3D 点云平均点间距评估