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轴为一个线段.问题转换成用最少 ...
随机推荐
- BZOJ 1923 外星千足虫(高斯消元)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1923 题意:有n个数字,m次测试.每个数字为0或者1.每次测试选出一些数字出来把他们加起 ...
- SecureCRT访问开发板linux系统
前言: 最近在用OK6410开发板跑linux系统,经常在终端上敲一些指令,无奈开发板屏幕太小用起来非常不方便,所以使用终端一款能运行在windows上的软件与开发板连接,直接在电脑上操作开发板了,这 ...
- rapidxml使用
以前都是用tinyxml,这次开发中解析xml配置文件像尝试一下rapidxml,据说效率很高... RapidXml Manual: http://rapidxml.sourceforge.net/ ...
- 如何使用 Java 测试 IBM Systems Director 的 REST API
转自: http://www.ibm.com/developerworks/cn/aix/library/au-aix-systemsdirector/section2.html 如何使用 Java ...
- 循环中不要放入openSession()
for(Shop s:list) { System.out.println(s.getName()); String sql="select shopId,sum(ele_bank+ele_ ...
- MyBatis 实践 -配置
MyBatis 实践 标签: Java与存储 Configuration mybatis-configuration.xml是MyBatis的全局配置文件(文件名任意),其配置内容和顺序如下: pro ...
- TIOBE 2015年5月编程语言排行榜 Visual Studio系列在上升
TIOBE 编程语言社区排行榜是编程语言流行趋势的一个指标,每月更新,这份排行榜排名基于互联网上有经验的程序员. 课程和第三方厂商的数量.排名使用著名的搜索引擎(诸如 Google.MSN.Yahoo ...
- json格式的字符串使用string.Format()方法报错:输入字符串的格式不正确
解决:把大括号转义一下就可以了啊,大括号的转义是两个{{ 结尾是}} 今天看同事写的代码,发现他在使用string.format拼接类似json格式的数据时,大括号多了一对,感觉不对就查了查 ...
- AngularJS promise()
实例说明一 <!DOCTYPE html> <html ng-app="my-app"> <head> <meta charset=&qu ...
- Java [leetcode 6] ZigZag Conversion
问题描述: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...