您的位置:首页 > 其它

ZOJ Problem Set - 1200 (Mining)

2014-08-11 11:25 411 查看
//这是一道关于优先队列(堆)的题,题目并不是很难,但是通过的只有18.10%;

//题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1200
#include<iostream>

#include<vector>

#include<functional>

#include<queue>

using namespace std;

priority_queue<int, vector<int>, greater<int> > rq; //定义一个最小堆,用来表示每个机器人到达矿场的时间

int S, W, C, K, M;

int main()

{

 int i, n, a;

 while (cin >> S >> W >> C >> K >> M)

 {

  while (!rq.empty())

  {

   rq.pop();

  }

  n = 9999 / C + 1;

  for (i = 1; i <= K; i++)

  {

   rq.push(i*M + S);

  }

  int time = rq.top();   //time表示当前一个机器人进入矿场的时间。

  for (i = 0; i < n-1; i++)

  {

   rq.pop();

   rq.push(2 * S + time+W);

   if (rq.top() - time <= W)

   {

    time += W;

   }

   else

   {

    time = rq.top();

   }

  }

  time += S+W;

  cout << time << endl;

 }

 return 0;

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: