博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVALive 7464 Robots(模拟)
阅读量:4325 次
发布时间:2019-06-06

本文共 3385 字,大约阅读时间需要 11 分钟。

7464Robots

Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg,Y=fY1;:::;Yng, and a baseB. Each robot has a data and we would like to compute the sum of datafrom all robots and deliver it to the base. In order to do so a robot can send its data to another robotor 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 inXcan 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. Thatis, 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 robotX1inXand two robotsY1andY2inY. We also assume thatxis 1 andyis 10. At the beginningY1can sendits data toY2andX1can send its data to the base. After 1 second the base will know the data ofX1.However, only after 10 secondsY2will have the data ofY1, add its own data, and send the sum to thebase. After 20 seconds the base receives the sum of data fromY1andY2, adds the data fromX1, andhas the final sum. The entire summation will take 20 seconds.Now let us try a different schedule. At beginningY1sends data to the base, andY2sends data toX1, and both can complete after 10 seconds. Finally X1 starts sending the sum of data from Y2 anditself to the base after 10 seconds, and the entire summation can finish in 11 seconds.Now givenm,n(the numbers of robots in X and Y),x, andy, please determine the minimumnumber of seconds to finish the summation.Constraints•1x<y1000.•0m<1200.•0n<500.

Input

The input consists of multiple test cases. First line contains a single integertindicating the number oftest cases to follow. Each of the nexttlines 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 fromall robots.

Sample Input

11  10  1  2

Sample Output

11

题目意思:有x,y两种类型的机器人各n个和m个,还有一个基地B,x型的机器人将其货物运到基地或其他机器人上需要x秒,y型的机器人将其货物运到基地或其他机器人上需要y秒,同一时刻每个机器人只能发送给一个对象,也只能接受一个对象的货物,基地在同一时刻也只能接受一个机器人的货物,问你如何搭配才能花费最短的时间将所有的货物运送到基地。

解题思路:这道题当时做的时候理解错意思了,但稀里糊涂地AC了,昨天整理博客的时候发现这个题跟我最初理解的意思完全不一样,看了看同学的代码,发现同一组样例结果不同却都能过,我想这道题判题的时候的样例怕是非常水。。。。这道题还是选择模拟整个运送过程比较好。因为y类机器人的传输时间肯定大于x类机器人的传输时间,因此我们先处理y类机器人!当y类机器人的数量还有剩余时,我们先拿出一个来给Base,剩下的如果m >= n  则先挑出n 个 给x类机器人,剩下m-n进行合并!直到y类处理完为止!然后同样的方法处理x类机器人,直到x类没有为止!

#include 
#include
#include
using namespace std;int main(){ int x,y,m,n; int T; scanf("%d",&T); while(T--) { scanf("%d %d %d %d",&x,&y,&n,&m); int ans=0; while(m) { m--;///y先送一个给base ans+=y; if (m>=n)///如果y的数量大于x的数量 { m=(m-n)/2+(m-n)%2;///送到x的数量+自我合并的数量 } else///如果y的数量小于x的数量,x类型的自我合并 { n=(n+m)/2+(n+m)%2; } } while(n) { n--; n=n/2+n%2; if(n==0) { break; } ans+=x; } printf("%d\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/wkfvawl/p/10508912.html

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第1节零基础快速入门SpringBoot2.0_4、快速创建SpringBoot应用之自动创建web应用...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_8、SpringBoot基础HTTP接口GET请求实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_6、SpringBoot2.xHTTP请求配置讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_10、常用json框架介绍和Jackson返回结果处理...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_9、SpringBoot基础HTTP其他提交方法请求实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_12、SpringBoot2.x文件上传实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_11、SpringBoot2.x目录文件结构讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第三节SpringBoot热部署devtool和配置文件自动注入实战_15、SpringBoot2.x配置文件讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_13、jar包方式运行web项目文件上传和访问...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_17、SpringBootTest单元测试实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第三节SpringBoot热部署devtool和配置文件自动注入实战_14、SpringBoot2.x使用Dev-tool热部署...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_19、SpringBoot个性化启动banner设置debug日志...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第三节SpringBoot热部署devtool和配置文件自动注入实战_16、注解配置文件自动映射到属性和实体类实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_20、SpringBoot2.x配置全局异常实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_18、SpringBoot测试进阶高级篇之MockMvc讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_36、SpringBoot整合mybatis之事务处理实战...
查看>>