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=;
while(n>m)
{
time+=y;
n=n--m;
}
if(n)
{
n--;
time+=y;
int tot=m-n;
int ci=y/x;
while(ci)
{
tot=(tot+)/;
ci--;
}
m=n+tot;
goto endw;
}
else
{
endw:;
while(m)
{
m--;
time+=x;
m=(m+)/;
}
}
cout<<time<<endl;
}
return ;
}

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

  1. 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

    比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...

  2. ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))

    祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...

  3. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  4. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. 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/Ot ...

  6. 【转】lonekight@xmu·ACM/ICPC 回忆录

    转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...

  7. 【转】ACM/ICPC生涯总结暨退役宣言—alpc55

    转自:http://hi.baidu.com/accplaystation/item/ca4c2ec565fa0b7fced4f811 ACM/ICPC生涯总结暨退役宣言—alpc55 前言 早就该写 ...

  8. 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/O ...

  9. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  10. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

随机推荐

  1. ScrollView 里的 EditText 与输入法的用例

    情景是这样的: 我希望页面可以滚动,因为长页面,内容多,必须滚动来满足不同手机的显示 点击 EditText 输入法弹出来,并将布局顶起来,并且EditText有足够的显示空间 进入页面时,输入法不能 ...

  2. 【java并发】传统线程技术中创建线程的两种方式

    传统的线程技术中有两种创建线程的方式:一是继承Thread类,并重写run()方法:二是实现Runnable接口,覆盖接口中的run()方法,并把Runnable接口的实现扔给Thread.这两种方式 ...

  3. SQL Server排序函数row_number和rank的区别

    SQL Server排序函数row_number和rank的区别 直接看测试结果 declare @table table(name varchar(100),amount int, memo var ...

  4. IIS集成模式下,URL重写后获取不到Session值

    近期给公司网站添加了伪静态功能,但是今天发现了在伪静态的页面中,Session值是获取不到的. 原因是在伪静态请求的时候,Session请求被“过滤”掉了. 开始是把web.config文件中的mod ...

  5. JS原生第二篇 (帅哥)

    1.1 Javascript 作用  1.  网页特效 2. 用户交互 3. 表单验证 Js  就是可以用来控制   结构  和 样式 . 1.2  体验js   认识常用的三个输出语句.  都属于 ...

  6. stackView的隐藏与显示注意事项

    1.想要通过变换stackView的y值来让stackView显现/隐藏,同时让其中的button能点击响应,得用topCons 2.导航栏的tinBar要设置为非透明状态

  7. MySQL5.6忘记root密码(win平台)

    1.首先net stop mysql服务,并且切换到任务管理器,有与mysql有关的,最好关闭进程. 2.运行CMD命令切换到MySql安装bin目录,下面是我的mysql安装目录 cd  C:\Pr ...

  8. js获取url地址中的参数

    <script type="text/javascript"> function GetQueryString(name) { var reg = new RegExp ...

  9. php常见的面试题目

    一. 基本知识点1.1 HTTP协议中几个状态码的含义:503 500 401 403 404 200 301 302...200 : 请求成功,请求的数据随之返回.301 : 永久性重定向.302 ...

  10. Android基于mAppWidget实现手绘地图(一)--简介

    http://lemberg.github.io/mappwidget/user_guide.html 最近在看一些导游类应用,发现一些景区的导览图使用的完全是自定义地图,也就是手绘地图.这种小范围使 ...