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;
}
时间: 2024-12-27 09:14:12

ACm-ICPC Live Archive 7464---Robots的相关文章

《ACM/ICPC 算法训练教程》读书笔记一之数据结构(堆)

书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了集训队final的意见买的,感觉还是不错滴. 相对于其他ACM书籍来说,当然如书名所言,这是一本算法训练书,有着大量的算法实战题目和代码,尽管小编还是发现了些许错误= =,有部分注释的语序习惯也有点不太合我的胃口.实战题目较多是比较水的题,但也正因此才能帮助不少新手入门,个人认为还是一本不错的算法书,当然自学还是需要下不少

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

ACM ICPC 2008–2009 NEERC MSC A, B, C, G, L

这套题是我上周日, 就是前天打得一场组队赛, 题目不太好找 题目链接:http://codeforces.com/gym/100861 在virtual judge 上也可以提交哦! A ACM ICPC Rules: 题目大意: 有很多所高校参加预选赛, 并在预选赛取得了排名, 但是对于每所学校, 除了MSU有4个名额之外其他大学只有两个名额( 也就是说, 只有每个大学的前2名进决赛(MSU前四名)&& 最多有10个队伍进入决赛), 高中队伍不能进入决赛. 给出预选赛的排名, 输出可以进

2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 212 Problem Description For a number,if the length of continuous odd digits is even and the length

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 208    Accepted Submission(s): 101 Problem Description You may not know this but it's a fact that Xinghai Square is

ACM/ICPC 之 经典动规(POJ1088-滑雪)

POJ1088-滑雪 将每个滑雪点都看作起点,从最低点开始逐个由四周递推出到达此点的最长路径的长度,由该点记下. 理论上,也可以将每一点都看作终点,由最高点开始计数,有兴趣可以试试. 1 //经典DP-由高向低海拔滑雪-求最长路 2 //Memory:372K Time:32 Ms 3 #include<iostream> 4 #include<cstring> 5 #include<cstdio> 6 #include<algorithm> 7 using

hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 735    Accepted Submission(s): 305 Problem Description Bob has N balls and A b

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m