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轴为一个线段.问题转换成用最少 ...
随机推荐
- C#编写媒体播放器--Microsoft的Directx提供的DirectShow组件,该组件的程序集QuartzTypeLib.dll.
使用C#编写媒体播放器时,需要用到Microsoft的Directx提供的DirectShow组件.用该组件前需要先注册程序集QuartzTypeLib.dll. 1.用QuartzTypeLib.d ...
- Anchor和Dock的区别
Dock的Bottom,整个控件填充下半部分,控件会被横向拉长 Anchor,仅仅是控件固定在下方,位置不会发生移动,自动锚定了此控件和父容器的底部的间隔 Anchor可以确定控件的相对位置不发生变化
- UVa 11330 (置换 循环的分解) Andy's Shoes
和UVa11077的分析很类似. 我们固定左脚的鞋子不动,然后将右脚的鞋子看做一个置换分解. 对于一个长度为l的循环节,要交换到正确位置至少要交换l-1次. #include <cstdio&g ...
- bzoj1832: [AHOI2008]聚会
写过的题... #include<cstdio> #include<cstring> #include<iostream> #include<algorith ...
- 基于AJAX的长轮询(long-polling)方式实现简单的聊天室程序
原理: 可以看:http://yiminghe.javaeye.com/blog/294781 AJAX 的出现使得 JavaScript 可以调用 XMLHttpRequest 对象发出 HTTP ...
- 利用nginx+lua+memcache实现灰度发布
一.灰度发布原理说明 灰度发布在百度百科中解释: 灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什 ...
- python - 沙盒环境 - virtualenv - 简明使用录
1. 不讲安装,没意思 2. 使用 virtualenv ENV # 建立环境,ENV你可以随便定,看起来像是 mkdir ENV cd ENV # 进目录呗 source bin/activate ...
- Android平台下实现录音及播放录音功能的简介
录音及播放的方法如下: package com.example.audiorecord; import java.io.File; import java.io.IOException; import ...
- Mac 配置jdk
1.打开终端,开始操作 cd ~touch.bash_profile vi .bash_profile 2.在此文本中添加以下内容 export JAVA_HOME=/Library/Java/Jav ...
- 【Ajax】实现注册页面判断用户名是否可用的提示—异步加载
效果如图 在注册或登录网站时,当我们输入错误格式的账号或信息时,会看到这种提示. 那怎么实现呢,通过ajax异步加载的方式,可以实现不刷新页面就显示出该提示. 实现 首先创建一个JSP,写一个简单的页 ...