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;
    }
  • 相关阅读:
    (转) Weblogic在Linux上节点服务器启动正常,计算机连接不上
    那些提升开发人员工作效率的在线工具
    (转) httpclient对cookie的处理
    (转) 修改weblogic部署的应用名称
    (转) oracle清空数据库脚本
    (转) weblogic 域,管理服务器,受管服务器,集群和机器的基本知识
    (转) Java中的负数及基本类型的转型详解
    (转)JAVA socket 进行十六进制报文交互测试
    liunx weblogic服务启停脚本
    转(HBuilder 打包流程)
  • 原文地址:https://www.cnblogs.com/chen9510/p/5658602.html
Copyright © 2011-2022 走看看