UVALive 7464 Robots (贪心)
Robots
题目链接:
http://acm.hust.edu.cn/vjudge/contest/127401#problem/K
Description
http://7xjob4.com1.z0.glb.clouddn.com/168817810b54cfa4ffaebf73d3d1b0c5
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
11
##题意:
有X和Y两类机器人各n m个,现在要将所有机器人上的信息传送到基点Base.
同一时刻每个机器人(包括Base)只能发给一个对象,也只能接受一个对象的信息.
X类的机器人发送数据的时间是x,Y类的是y. (x
##题解:
直接按样例的思路来贪心即可.
首先,Y的发送时间大于X的发送时间. 把Y的信息先转存到X(在这同时选一个Y发送到BASE) 一定比把所有Y依次传送到BASE要好.
同一边的可以先两两合并再发送.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 300
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
int main(int argc, char const *argv[])
{
//IN;
int t; cin >> t;
while(t--)
{
int x,y,m,n;
cin >> x >> y >> m >> n;
int ans = 0;
while(n > m) {
ans += y;
n -= m + 1;
}
if(n) {
ans += y;
int last = m - n;
int cur = 0;
while(last > 0) {
if(cur + x > y) break;
cur += x;
last /= 2;
}
m = last + n;
}
while(m > 0) {
ans += x;
m /= 2;
}
printf("%d\n", ans);
}
return 0;
}
UVALive 7464 Robots (贪心)的更多相关文章
- UVALive 7464 Robots(模拟)
7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...
- UVAlive 2911 Maximum(贪心)
Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...
- uvalive 2911 Maximum(贪心)
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...
- UVALive - 4225(贪心)
题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...
- UVALive 4850 Installations 贪心
题目链接 题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...
- UVALive 4863 Balloons 贪心/费用流
There will be several test cases in the input. Each test case will begin with a line with three inte ...
- UVALive - 6268 Cycling 贪心
UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:
- UVALive 4731 dp+贪心
这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...
- UVALive 3835:Highway(贪心 Grade D)
VJ题目链接 题意:平面上有n个点,在x轴上放一些点,使得平面上所有点都能找到某个x轴上的点,使得他们的距离小于d.求最少放几个点. 思路:以点为中心作半径为d的圆,交x轴为一个线段.问题转换成用最少 ...
随机推荐
- Android L 使用ART能提高多少性能?
点击打开链接 刚刚结束的 Google I/O 大会上,Android 下一代操作系统「L」带来不少惊喜.新系统运行更快.更省电. 然而开发者对这个新系统也有颇多疑问,比如新的运行模式 ART 对开发 ...
- JS创建类以及类的方法(StringBuffeer类)
创建StringBuffer类以及toString,append()方法 //创建一个StringBuffer类 ,此类有两个方法:一个是append方法一个是toString方法 function ...
- Internet Explorer for Mac the Easy Way: Run IE 7, IE8, & IE9 Free in a Virtual Machine
From link: http://osxdaily.com/2011/09/04/internet-explorer-for-mac-ie7-ie8-ie-9-free/ If you’re ...
- bzoj2482
还是像以前那样维护下次出现位置,计算影响 其实不难,思维盲点,受到做最大子段和的影响 其实这里可以直接维护当前每个位置的子段和,再记录一个历史最大和 当然tag也需要记录当前tag和历史(距离上次pu ...
- uva12230Crossing Rivers
数学期望. 过每条河的时间的可能在[L/v,3*L/v]间均匀分布,数学期望为2*L/v. 然后在加上在陆上走的时间. #include<cstdio> #include<algor ...
- 在ASP.NET中如何判断用户IE浏览器的版本
f ( Request.Browser.MajorVersion == ) { // to do } ................................................. ...
- REVOKE DBA权限要小心
REVOKE DBA权限要小心 转载:http://blog.csdn.net/lwei_998/article/details/6133557 发现某些用户有DBA权限的时候,为了安全,一般我们 ...
- 试图从数据库 ‘UFData_001_2003' 中提取的逻辑页 (1:10720) 属于对象 '0',而非对象 'syscolumns'
数据库可以使用,可以备份,但对备份进行恢复时报错,使用sp_attach_db对两个物理文件进行连接时,报同样错误: 服务器: 消息 605,级别 21,状态 1,行 1 试图从数据库 ‘UFData ...
- 使用java解析和制作二维码
项目结构 文件源码 QR.zip 第一步:导入zxing的两个架包 core.jar和javase.jar 第二步:使用工具类 MatrixToImageWriter.java package uti ...
- Java [Leetcode 112]Path Sum
题目描述: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding ...