题目描述
A mining base needs to build some robots to collect at least 10000 units of resource. Each robot will start from the base, reach the diggings in S minutes, work for W minutes, and then take C units of resource back to the base in S minutes.
To speed up this procedure, K robots will be built at the base. It takes M minutes to produce one robot. A robot will be set to start working immediately after it is built, and producing the next robot will be on line right after. This procedure continues untill all the robots are built.
Due to the limitation of the mining equipments, there can be only one robot digging at the working area. That is, it is only after the currently working robot finishes its collecting work and starts getting back to the base that the next robot can work at the diggings.
Now it is your job to write a program to simulate this procedure, and find out how many minutes it will take to collect at least 10000 units of resource.
输入
There are several lines of input. Each line contains a test case which consists of 5 integers, namely S, W, C, K, and M.
输出
For each test case, you are asked to output an integer t, which is the number of minutes taken to collect at least 10000 units of resource.
样例输入
复制样例数据
10 20 10 1 5
样例输出
40005
来源/分类
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int s,w,c,k,m;
while(cin>>s>>w>>c>>k>>m)
{
priority_queue<int,vector<int>,greater<int> >q;
int num=9999/c+1;
for(int i=1; i<=k; i++)
{
q.push(i*m+s);//每個機器人到達礦區的時間。
}
int time=q.top();
for(int i=1; i<num; i++)
{
q.pop();
q.push(2*s+w+time);//前一个机器人返回继续到达矿区的时间
if(q.top()<=time+w)//如果后面一个机器人到达时间小于前一个工作完成,后一个机器人到达矿区的时间需要加上等待的w。
time+=w;
else
time=q.top();
}
time+=s+w;
cout<<time<<endl;
}
return 0;
}