zoukankan      html  css  js  c++  java
  • ACm-ICPC Live Archive 7464---Robots

    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;
    }
  • 相关阅读:
    架构师的成长之路初片~ntp时间同步
    架构师的成长之路初片~水晶头的颜色排序
    架构师的成长之路初片~Python-邮件(smtplib)、requests模块、API接口调用
    架构师成长之路之~调优思维
    架构师的成长之路初片~python~调整背景及滚轮+各种快捷键
    架构师成长之路之~Node.js安装篇
    微服务技术栈
    C#资源释放(托管资源、非托管资源)
    Beyond Compare 4 密匙
    MySql批量导入 .netcore命名空间完全相同问题
  • 原文地址:https://www.cnblogs.com/chen9510/p/5658602.html
Copyright © 2011-2022 走看看