HDU 4952 Poor Mitsui(贪心)
HDU 4957 Poor Mitsui
思路:利用相邻交换法去贪心就可以。注意容积为0的情况,这是个坑点
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 45; struct SB {
int a, b;
} sb[N]; bool cmp(SB x, SB y) {
return x.b * y.a < x.a * y.b;
} int t, n, v; double solve() {
for (int i = 0; i < n; i++)
if (sb[i].b && sb[i].a >= v) return -1;
double ans = 0;
for (int i = 0; i < n; i++) {
if (sb[i].b == 0) continue;
ans = ans + (sb[i].b + sb[i].a * ans) / (v - sb[i].a);
}
return ans;
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &v);
for (int i = 0; i < n; i++)
scanf("%d", &sb[i].a);
for (int i = 0; i < n; i++)
scanf("%d", &sb[i].b);
sort(sb, sb + n, cmp);
printf("%.0f\n", solve());
}
return 0;
}
HDU 4952 Poor Mitsui(贪心)的更多相关文章
- HDU 4957 Poor Mitsui
题解:记答案为ans,已知,对一个确定的顺序,计算所用的时间长短就是从最后向前计算,计算方法如下: ans+=(p[i].b+ans*p[i].a)/(v-p[i].a) 那么,应该如何调整顺序使得答 ...
- hdu 4803 Poor Warehouse Keeper(贪心+数学)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26005267 题目链接:hdu 4803 P ...
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- HDU 4803 Poor Warehouse Keeper (贪心+避开精度)
555555,能避开精度还是避开精度吧,,,,我们是弱菜.. Poor Warehouse Keeper Time Limit: 2000/1000 MS (Java/Others) Memor ...
- HDU 4803 Poor Warehouse Keeper(贪心)
题目链接 题意 :屏幕可以显示两个值,一个是数量x,一个是总价y.有两种操作,一种是加一次总价,变成x,1+y:一种是加一个数量,这要的话总价也会相应加上一个的价钱,变成x+1,y+y/x.总价显示的 ...
- HDU 5835 Danganronpa (贪心)
Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
- HDU 5821 Ball (贪心)
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- hdu 4004 (二分加贪心) 青蛙过河
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...
- Saving HDU(hdu2111,贪心)
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- Java从零开始学二十八(Math类和Random类)
一.Math概述 提供了常用的数学运算方法和两个静态常量E(自然对数的底数)和PI(圆周率) 二.常用方法 package com.pb.demo1; public class MathTest { ...
- Shell解释器(学习笔记四)
一.Shell解释器 shell解释器,用户和操作系统内核之间的桥梁 shell介于操作系统内核与用户之间,负责接收用户输入的操作指令(命令),并运行和解释,将需要执行的操作传递给操作系统内核并执行 ...
- SecureCRT 命令行备注
> 查出某个域名绑定的IP nslookup api.kaixin001.com Non-authoritative answer: Name: a.kaixin001.com Addre ...
- Starting MySQL.. ERROR! The server quit without updating PID file (/gechong/mysqldata/10-9-23-119.pid).
配置文件修改错误了,还原一下重启服务就OK了. # /etc/init.d/mysql start
- 简单说说Ubuntu利用bzr源码安装OpenERP7.0的操作步骤
1.修改Ubuntu国内更新源,具体方法自己baidu.google. 修改更新源后,更新系统 sudo apt-get update sudo apt-get upgrade 复制代码 2.安装Po ...
- ibatis 批量更新(一)
1.4.2.3 批量修改 支持单个动态更新.批量动态更新 <update id="updateCONSULT_SCHEDULEDynamic" parameterClas ...
- maven org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60
maven org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant poo ...
- Oracle常用标准表
一.INV(库存) 子库存:mtl_secondary_inventories 事物处理:mtl_material_transactions mmt 事务处理来源类型:mtl_txn_source_t ...
- JUC-Callable
实现线程的方式有四种: 1,实现runnable接口: 2,继承Thread. 3,也就是本节的Callable接口. 4,使用线程池. 区别: 实现Callable接口的方式,相较于实现Runnab ...
- LR函数基础(一)
函数用到:web_reg_find(). lr_log_message(). lr_eval_string().strcmp().atoi() Action(){ web_reg_find(&q ...