1014. Waiting in Line @ PAT (Advanced Level) Practise

2023-12-12 10:38

本文主要是介绍1014. Waiting in Line @ PAT (Advanced Level) Practise,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

NOTICE:

1.题目中讲的“Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.” 其实是说开始服务时间不能超过17:00而不是服务结束时间。

2.更简洁的代码:http://blog.csdn.net/huajh7/article/details/7918144 

3.这样的时间模拟方式是有问题的,在这里没有出现问题是因为所有顾客是同时到达的。在A1017中的类似问题则不能用这种方式。比如一个最小的timeToGo是3分钟,如果期间一个顾客到来,且窗口有空的话,则这个顾客也需要等到3分钟时被服务。一个较好的方式是窗口用优先队列,窗口结构中记录窗口时间。To:A1017

#include<iostream>
#include<deque>
#include<vector>
#include<string>
#include<sstream>using namespace std;int N,M,K,Q;
int timeFinishArray[1004];
int tCount=0;
struct customer{int id;int time;
};
deque<customer> qc;
vector< deque<customer> > vqc;stringstream ss;void initialization();
void dowork();
string convertToTime(int);
void printResult();
bool fillIn();
bool haveCustomer();int main()
{initialization();while(haveCustomer()){dowork();}printResult();return 0;
}
void initialization()
{cin>>N>>M>>K>>Q;for(int i=0;i<N;i++){deque<customer> tmpq;vqc.push_back(tmpq);}for(int i=0;i<K;i++){timeFinishArray[i]=-1;struct customer tmpC;tmpC.id=i;cin>>tmpC.time;qc.push_back(tmpC);}while(fillIn());return;
}
void dowork()
{int minTimeDeque=0;int minTimeToGo=0;for(int i=0;i<N;i++){if(!vqc[i].empty()){if(vqc[i].front().time<minTimeToGo || minTimeToGo==0){minTimeToGo=vqc[i].front().time;}}}if(minTimeToGo==0)return;tCount+=minTimeToGo;for(int i=0;i<N;i++){if(!vqc[i].empty()){vqc[i].front().time-=minTimeToGo;if(vqc[i].front().time==0){timeFinishArray[vqc[i].front().id]=tCount;vqc[i].pop_front();if(tCount>=540)vqc[i].clear();}}}if(tCount<540){while(fillIn());}else{qc.clear();}return;
}
string convertToTime(int i)
{string s;int h,m;ss.clear();ss.str("");// important !h=i/60 + 8;m=i%60;if(h<10)ss<<0;ss<<h<<":";if(m<10)ss<<0;ss<<m;s=ss.str();return s;
}void printResult()
{int c;for(int i=0;i<Q;i++){cin>>c;c--;if(timeFinishArray[c]==-1)cout<<"Sorry"<<endl;elsecout<<convertToTime(timeFinishArray[c])<<endl;}return;   
}
bool fillIn()
{if(qc.size()==0)return false;int minDeque=0;for(int i=1;i<N;i++){if(vqc[i].size()<vqc[minDeque].size())minDeque=i;}if(vqc[minDeque].size()<M){vqc[minDeque].push_back(qc.front());qc.pop_front();return true;}elsereturn false;
}bool haveCustomer()
{for(int i=0;i<N;i++){if(!vqc[i].empty()){return true;}}return false;
}


这篇关于1014. Waiting in Line @ PAT (Advanced Level) Practise的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/484308

相关文章

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

Debugging Lua Project created in Cocos Code IDE creates “Waiting for debugger to connect” in Win-7

转自 I Installed Cocos Code IDE and created a new Lua Project. When Debugging the Project(F11) the game window pops up and gives me the message waiting for debugger to connect and then freezes. Also a

MiniCPM-V: A GPT-4V Level MLLM on Your Phone

MiniCPM-V: A GPT-4V Level MLLM on Your Phone 研究背景和动机 现有的MLLM通常需要大量的参数和计算资源,限制了其在实际应用中的范围。大部分MLLM需要部署在高性能云服务器上,这种高成本和高能耗的特点,阻碍了其在移动设备、离线和隐私保护场景中的应用。 文章主要贡献: 提出了MiniCPM-V系列模型,能在移动端设备上部署的MLLM。 性能优越:

PAT甲级-1044 Shopping in Mars

题目   题目大意 一串项链上有n个钻石,输入给出每个钻石的价格。用m元买一个连续的项链子串(子串长度可为1),如果不能恰好花掉m元,就要找到最小的大于m的子串,如果有重复就输出多个,按递增顺序输出子串的前端和后端索引。 原来的思路 取连续的子串使和恰等于m,没有恰等于就找最小的大于。可以将子串依次累加,使得每个位置都是起始位置到该位置的序列和,整个数组显递增顺序,就可以用右边减左边

PAT (Advanced Level) Practice——1011,1012

1011:  链接: 1011 World Cup Betting - PAT (Advanced Level) Practice (pintia.cn) 题意及解题思路: 简单来说就是给你3行数字,每一行都是按照W,T,L的顺序给出相应的赔率。我们需要找到每一行的W,T,L当中最大的一个数,累乘的结果再乘以0.65,按照例子写出表达式即可。 同时还需要记录每一次选择的是W,T还是L

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from class path resource [bean1.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineN

line.split(‘ ‘).map(Number)

line.split(' ').map(Number) 是一个常见的 JavaScript 操作,分为两部分来理解: line.split(' '): 这一部分将字符串 line 按照空格 ' ' 分割成一个数组。假设 line 是 "1 2",那么 line.split(' ') 将返回 ["1", "2"],这是一个由字符串组成的数组。 .map(Number): map() 是 Jav

Command line is too long. Shorten command line for DisplayApplication (1) or

微服务项目启动类起不来,如下 解决办法:IEDA开发环境下 找到你的项目下面的.idea\workspace.xml 添加一个property : <property name="dynamic.classpath" value="true" /> 帮同事看的问题,自己测试没问题就关闭了。图片借用网上的。 参考:参考

扫描线Sweep Line算法总结

扫描线算法,推荐还是用标准的模板去写,treemap只适合于求最大的overlap个数的题目,其余的不能用treemap来解,所以推荐还是用event的思想去+1, -1然后排序扫描的方法可以用来解所有的题型; Number of Airplanes in the Sky 思路:经典扫描线算法:把interval起飞和降落做为event,全部打散,按照时间排列,同时时间相等的,按照降落在前面,起

N-ary Tree Level Order Traversal

Input: root = [1,null,3,2,4,null,5,6]Output: [[1],[3,2,4],[5,6]] 思路:就是一个queue的level order 收集; /*// Definition for a Node.class Node {public int val;public List<Node> children;public Node() {}pu