bzoj 1110 贪心 + 进制转换
思路:感觉脑洞好大啊。。。 因为每两个砝码其中一个都是另一个的倍数,我们可以知道砝码的种数很少,我们将所有容器的
容量都转换成用这些砝码的重量的进制表示,然后将所有砝码排序,然后贪心地取,取到不能再取。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int n, m, w[N], a[N], b[N], cnt[], tot;
int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d", &w[i]);
} for(int i = ; i <= m; i++) {
scanf("%d", &a[i]);
b[tot++] = a[i];
} sort(b, b + tot);
tot = unique(b, b + tot) - b;
reverse(b, b + tot); for(int i = ; i <= n; i++) {
int now = w[i];
for(int j = ; j < tot && now; j++) {
cnt[j] += now / b[j];
now = now % b[j];
}
} int ans = ; sort(a + , a + + m); for(int i = ; i <= m; i++) {
for(int j = tot - ; j >= ; j--) {
if(b[j] == a[i]) {
if(cnt[j]) {
cnt[j]--;
ans++;
break;
} else {
int pos = -;
for(int k = j - ; k >= ; k--) {
if(cnt[k]) {
pos = k;
break;
}
}
if(pos == -) {
i = m + ;
break;
}
for(int k = pos + ; k <= j; k++) {
cnt[k - ]--;
cnt[k] += b[k - ] / b[k];
}
ans++;
cnt[j]--;
break;
}
}
}
} printf("%d\n", ans);
return ;
}
/*
*/
bzoj 1110 贪心 + 进制转换的更多相关文章
- Delphi进制转换(二进制/十进制/十六进制)
http://www.cnblogs.com/ywangzi/archive/2012/12/12/2815219.html Delphi进制转换(二进制/十进制/十六进制) 2009-11-2 ...
- C语言关于进制转换,补码, 整数的位操作
菜单导航: 1.二进制.八进制.十进制.十六进制的相互转换 2.原码.反码.补码 3.举例证明整数在计算机内是以补码的形式存在(以负数为例) 4.整数的位操作:按位且&.或|.异或^.取反~ ...
- C语言基础——进制转换 / 数据表示
第一部分:进制转换 二进制:由0~1构成,逢2进1 八进制:由0~7构成,逢8进1 十六进制:由0~9.A~F构成,逢16进1 两个基本概念 基数:n进制基数为n 123.4 = 1*10^2 + 2 ...
- Go 获取键盘输入,进制转换
#### Go 获取键盘输入,进制转换 最近爱上<<珂矣的心灵独语>> 连续听一下礼拜也不觉得厌: 喜欢她的宁静与安然,喜欢她的坦荡与欢喜,喜欢她的禅意与智慧; ***撑着一苇 ...
- SQL Server 进制转换函数
一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...
- [No000071]C# 进制转换(二进制、十六进制、十进制互转)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- JS中的进制转换以及作用
js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...
- 结合stack数据结构,实现不同进制转换的算法
#!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...
- 进制转换( C++字符数组 )
注: 较为简便的方法是用 整型(int)或浮点型(long.double 注意:该类型不一定能够准确存储数据) 来存放待转换的数值,可直接取余得到每一位数值 较为稳定的方法是用 字符数组储存待转换的数 ...
随机推荐
- 使用gulp进行css、js压缩
var gulp = require('gulp'); var cleanCSS = require('gulp-clean-css'); var concatCss = require('gulp- ...
- STL源码分析-string
http://note.youdao.com/noteshare?id=c9b53b7d3379939aae7c05d1ea141a42
- ZABBIX 3.0 配置监控NGINX性能【OK】
1.在agent端查看配置: nginx -V //查看编辑时是否加入状态监控模块:--with-http_stub_status_module --with-http_gzip_static_mod ...
- [吴恩达机器学习笔记]14降维5-7重建压缩表示/主成分数量选取/PCA应用误区
14.降维 觉得有用的话,欢迎一起讨论相互学习~Follow Me 14.5重建压缩表示 Reconstruction from Compressed Representation 使用PCA,可以把 ...
- /etc/rc.d/里文件的作用
rc.sysinit指的是系统启动不管进哪个运行级别必须做的初始化工作, rcn.d目录指的是系统进对应n的运行级别时候系统必须做的工作,目录下S打头的服务指进此运行级别时候启动的服务,而K打头的指离 ...
- GlusterFS + lagstash + elasticsearch + kibana 3 + redis日志收集存储系统部署 01
因公司数据安全和分析的需要,故调研了一下 GlusterFS + lagstash + elasticsearch + kibana 3 + redis 整合在一起的日志管理应用: 安装,配置过程,使 ...
- 查询timestamp类型数据
$where=" roleid = 8 and lizhi = 0 and branchid IN (".implode(",",$ids).") a ...
- LeetCode之数据流中第一个唯一的数字
使用一个Map维护数字出现的次数,使用一个链表维护只出现一次的数,使用一个变量记录是否找到过终止数字. AC代码: public class Solution { /* * @param : a co ...
- Django之动态验证码的生成
kind.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- jquery.cookie.js——jquery的cookie插件
一.JS文件 /*! * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Copyright 2 ...