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=;
- 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的更多相关文章
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛
比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...
- ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))
祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...
- 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 ...
- 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 ...
- 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 ...
- 【转】lonekight@xmu·ACM/ICPC 回忆录
转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...
- 【转】ACM/ICPC生涯总结暨退役宣言—alpc55
转自:http://hi.baidu.com/accplaystation/item/ca4c2ec565fa0b7fced4f811 ACM/ICPC生涯总结暨退役宣言—alpc55 前言 早就该写 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- javascript原型对象prototype
“我们创建的每一个函数都有一个prototype(原型)属性,这个属性是一个指针,指向一个对象,而这个对象的用途是包含可以由特定类型的所有实例共享的属性和方法.” 引用类型才具有prototype属性 ...
- java基础,继承类题目:编写一个Java应用程序,该程序包括3个类:Monkey类、People类和主类 E
21.编写一个Java应用程序,该程序包括3个类:Monkey类.People类和主类 E.要求: (1) Monkey类中有个构造方法:Monkey (String s),并且有个public vo ...
- TSQL 去除重复值
数据去重主要分为两种情况:第一种是保证Select的全部列无重复:第二种是select的部分字段无重复,而其他字段取特定值. 1,对select的全部字段去重,直接使用distinct 函数 2,对s ...
- JSP网站开发基础总结《七》
按照计划本篇将为大家总结搜索功能的两种实现:确定搜索与模糊搜索.所谓精确搜索便是指,根据用户的输入的搜索内容,在数据库中寻找具有一一对应的关系的数据,一般都是用户在数据库中的主键值.而模糊搜索,是一种 ...
- SQL*Loader之CASE3
CASE3 1. SQL文件 [oracle@node3 ulcase]$ cat ulcase3.sql set termout off rem Do not clean up table beca ...
- 打开都是“Smart Adobe CC Blocker v1.0”已损坏,打不开。 您应该将它移到废纸篓。
安全设置里允许任意来源打开就可以了 “系统偏好设置”->“安全性与隐私”->“允许从以下位置下载的应用程序”->任何来源.
- 使用 SVG 实现一个漂亮的页面预加载效果
今天我们要为您展示如何使用 CSS 动画, SVG 和 JavaScript 创建一个简单的页面预加载效果.对于网站来说,这些预载入得画面提供了一种创造性的方法,使用户在等待内容加载的时候不会那么无聊 ...
- Web 前端开发精华文章集锦(jQuery、HTML5、CSS3)【系列十九】
<Web 前端开发精华文章推荐>2013年第七期(总第十九期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和 C ...
- 决战JS
经过这几日的学习,测试和摸索,算是了解了一些关于javascript 的相关知识吧.学习过程中做出了一些小DEMO,现总结一下实现这些DEMO的基本思路,如有不妥或更为简便的方法,还希望大神拍砖,共同 ...
- jQuery.ajax()的相关参数及使用
jQuery.ajax(),有很多项参数,小弟菜鸟级别,有时候想不起来,现在记录下来便于以后查看,也欢迎大神指正. 常用的几类,可以称为模板样式写法: $.ajax({ url: "url& ...