码迷,mamicode.com
首页 > 其他好文 > 详细

ACm-ICPC Live Archive 7464---Robots

时间:2016-07-10 23:05:09      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

ACm-ICPC Live Archive 7464---Robots

Write a program to collect data from robots. We are given two sets of robots X = {X1, . . . , Xm}, Y = {Y1, . . . , Yn}, and a base B. Each robot has a data and we would like to compute the sum of data from all robots and deliver it to the base. In order to do so a robot can send its data to another robot or the base with the following constraints. • A robot can only send its data to one destination (a robot or the base) at a time. • A robot (or the base) can receive data from one robot at a time. • The base can not send data to anyone. • A robot in X can complete sending its data in x seconds. A robot in Y can complete sending its data in y seconds. The robots and the base can perform addition, so we can collect the final sum at the base. That is, we assume that after receiving a data, a robot or the base can perform an addition with zero time. Now let us illustrate this concept by an example. Let us consider a system with one robot X1 in X and two robots Y1 and Y2 in Y . We also assume that x is 1 and y is 10. At the beginning Y1 can send its data to Y2 and X1 can send its data to the base. After 1 second the base will know the data of X1. However, only after 10 seconds Y2 will have the data of Y1, add its own data, and send the sum to the base. After 20 seconds the base receives the sum of data from Y1 and Y2, adds the data from X1, and has the final sum. The entire summation will take 20 seconds. Now let us try a different schedule. At beginning Y1 sends data to the base, and Y2 sends data to X1, and both can complete after 10 seconds. Finally X1 starts sending the sum of data from Y2 and itself to the base after 10 seconds, and the entire summation can finish in 11 seconds. Now given m, n (the numbers of robots in X and Y ), x, and y, please determine the minimum number of seconds to finish the summation. Constraints • 1 ≤ x < y ≤ 1000. • 0 ≤ m < 1200. • 0 ≤ n < 500. Input The input consists of multiple test cases. First line contains a single integer t indicating the number of test cases to follow. Each of the next t lines contains four integers — x, y, m, n. Output For each test case, output on a single line the minimum number of seconds to sum up all numbers from all robots. Sample Input 1 1 10 1 2 Sample Output 1

代码如下:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int T;
    int x,y,n,m;
    cin>>T;
    while(T--)
    {
        cin>>x>>y>>m>>n;
        int time=0;
        while(n>m)
        {
            time+=y;
            n=n-1-m;
        }
        if(n)
        {
            n--;
            time+=y;
            int tot=m-n;
            int ci=y/x;
            while(ci)
            {
                tot=(tot+1)/2;
                ci--;
            }
            m=n+tot;
            goto endw;
        }
        else
        {
            endw:;
            while(m)
            {
                m--;
                time+=x;
                m=(m+1)/2;
            }
        }
        cout<<time<<endl;
    }
    return 0;
}

 

ACm-ICPC Live Archive 7464---Robots

标签:

原文地址:http://www.cnblogs.com/chen9510/p/5658602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!