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 (贪心)的更多相关文章

  1. UVALive 7464 Robots(模拟)

    7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...

  2. UVAlive 2911 Maximum(贪心)

    Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...

  3. uvalive 2911 Maximum(贪心)

    题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...

  4. UVALive - 4225(贪心)

    题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...

  5. UVALive 4850 Installations 贪心

    题目链接  题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...

  6. UVALive 4863 Balloons 贪心/费用流

    There will be several test cases in the input. Each test case will begin with a line with three inte ...

  7. UVALive - 6268 Cycling 贪心

    UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:

  8. UVALive 4731 dp+贪心

    这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...

  9. UVALive 3835:Highway(贪心 Grade D)

    VJ题目链接 题意:平面上有n个点,在x轴上放一些点,使得平面上所有点都能找到某个x轴上的点,使得他们的距离小于d.求最少放几个点. 思路:以点为中心作半径为d的圆,交x轴为一个线段.问题转换成用最少 ...

随机推荐

  1. MySQL select into 和 SQL select into

    现在有张表为student,我想将这个表里面的数据复制到一个为dust的新表中去,虽然可以用以下语句进行复制,总觉得不爽,希望各位帮助下我,谢谢.  answer 01: create table d ...

  2. Java 比较两张图片的相似度

    import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; /** * 比较两张图片 ...

  3. bzoj3275: Number

    最小割...然后推一下可知不能的情况必定为一奇一偶,于是s->奇->偶->t.跑最小割即可. #include<cstdio> #include<cstring&g ...

  4. jquery获取div距离顶部的距离

    获取元素到页面顶部距离的语句为: 1.jquery写法:$(“#divID”).offset().top //推荐 $("#vertical").position().top 2. ...

  5. 无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败。

    无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败. 在Asp.Net项目中使用WebClient或HttpWebRequest时出现以上错误 解决方案:把以下代码放在 ...

  6. python模拟http请求2

    发现了一个非常好用的第三方module:requests,模拟接口非常简单. 详细了解请移步:http://docs.python-requests.org/en/latest/ 非常不错 #!cod ...

  7. HDU 2544 最短路 (最短路,spfa)

    题意:中文题目 思路:spfa+SLF优化.关于SPFA的详情请戳我 #include <bits/stdc++.h> using namespace std; , INF=0x7f7f7 ...

  8. linux 定时任务调度Cron的用法详解

    在linux中,推荐使用crontab -e命令添加自定义的任务,退出后重启crond进程. 重新启动cron服务或重新加载cron配置,命令: 复制代码代码示例: /etc/rc.d/init.d/ ...

  9. 【C#学习笔记】List容器使用

    using System; using System.Collections.Generic; namespace ConsoleApplication { class Program { stati ...

  10. zoj 2770 Burn the Linked Camp (差分约束系统)

    // 差分约束系统// 火烧连营 // n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i- ...