UVALive 7464 Robots(模拟)
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 <cstdio>
#include <cstring>
#include <algorithm>
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=;
while(m)
{
m--;///y先送一个给base
ans+=y;
if (m>=n)///如果y的数量大于x的数量
{
m=(m-n)/+(m-n)%;///送到x的数量+自我合并的数量
}
else///如果y的数量小于x的数量,x类型的自我合并
{
n=(n+m)/+(n+m)%;
}
}
while(n)
{
n--;
n=n/+n%;
if(n==)
{
break;
}
ans+=x;
}
printf("%d\n",ans);
}
return ;
}
UVALive 7464 Robots(模拟)的更多相关文章
- UVALive 7464 Robots (贪心)
Robots 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/K Description http://7xjob4.com1.z ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- POJ-2632 Crashing Robots模拟
题目链接: https://vjudge.net/problem/POJ-2632 题目大意: 在一个a×b的仓库里有n个机器人,编号为1到n.现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令 ...
- UVALive 3971 Assemble(模拟 + 二分)
UVALive 3971 题意:有b块钱.想要组装一台电脑,给出n个配件的种类,名字,价格,品质因子.若各种类配件各买一个,总价格<=b,求最差品质配件的最大品质因子. 思路: 求最大的最小值一 ...
- UVALive 6451:Tables(模拟 Grade D)
VJ题目链接 题意:模拟输出表格 思路:模拟……很暴力 代码: #include <cstdio> #include <cstring> #include <cstdli ...
- Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
B. Testing Robots time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- UVALive 3634 数据结构模拟
这题真是坑啊,题意不明,其实就是往桟里面压入空的set集合,所以之前的询问大小都是只有0,只有add的时候,才会产生新的占空间的集合 用stack和set直接进行模拟 #include <ios ...
随机推荐
- 使用Message
Message按照定义解释就是topic内容的数据类型, 也称之为topic的格式标准. 1.结构与类型 基本的msg包括bool. int8. int16. int32. int64(以及uint) ...
- c模拟内存分配算法(首次适应算法,最佳适应算法,最坏适应算法)
#include<bits/stdc++.h> using namespace std; /*定义内存的大小为100*/ #define MEMSIZE 100 /*如果小于此值,将不再分 ...
- hadoop日常维护之问题解决01
执行hadoop任务遇到的问题: Caused by: org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /user/h ...
- Fiddler设置代理后,iphone手机无法访问网络的全面解决办法
好久不抓手机包,都有些忘记了,电脑上软件都在,原本是Fiddler4,现在已自动升级到V5. 入主题吧,首先Fiddler设置好代理,然后手机安装证书好了,设置手机代理,结果iphone无法访问网络, ...
- python新手第一天学习笔记-python循环控制和第一个python小游戏
Python的三种逻辑控制 1.python语法. python 是以缩进作为基本判断的.同一代码缩进需要保持一致.否则会报错 1.if 的三种循环 _age = 53 # 注意,input接受的都是 ...
- VIM - tab 相关的简单配置
1. 概述 vim 是强大的文本编辑器 使用 vim 前, 需要做些简单配置, 来让 vim 更符合自己的操作习惯 想看配置项的, 直接到最后 2. 准备 安装 vim 略 配置文件 位置 /etc/ ...
- JavaWeb总结(九)
过滤器 - 一个中间组件,用于拦截源数据和目的数据之间的消息 - 过滤二者之间传递的数据 Web应用上的过滤器 -驻留在Web服务器上的Web组件 -过滤从客户端传递到服务器端的请求和响应 单个过滤器 ...
- [Deep-Learning-with-Python]神经网络入手学习[上]
神经网络入手[上] [x] 神经网络的核心部分 [x] Keras介绍 [ ] 使用Keras解决简单问题:分类和回归 神经网络剖析 神经网络的训练与下列对象相关: 网络层Layers,网络层结合形成 ...
- <link rel="stylesheet" type="text/css" href="css/index.css">详解
整条语句的含义是: 调用一个外部的CSS样式文件.他是通过<link/>这个标签来调用的. 然后, href="css/index.css" 表示外部样式文件的路径, ...
- 菜鸟vimer成长记——第2.3章、insert模式
大部分的Vim 命令都在非插入模式中执行,不过有些功能在插入模式中会更好实现些. 如果没有输入当前文件不存在的新文本的需求时,建议通过其他模式来操作完成. 目的 掌握inser模式下常用操作的语法和概 ...