【习题 8-1 UVA - 1149】Bin Packing
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
每个背包只能装两个东西。
而且每个东西都要被装进去。
那么我们随意考虑某个物品。(不必要求顺序
这个物品肯定要放进某个背包里面的。
那么背包数递增。
那么剩余的空间。
只能装一个了。
要装谁呢?
肯定是尽可能装较大的.所以用upper_bound-1找一个最大的能装的装就可以了。
这样就能尽量减少体积较大的物品了。
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n,l;
multiset<int> myset;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
int kase = 0;
while (T--){
if (kase>0) cout << endl;
kase++;
myset.clear();
cin >> n >> l;
for (int i = 1;i <= n;i++) {
int x;
cin >> x;myset.insert(x);
}
int cnt = 0;
for (int i = 1;i <= n;i++){
if (myset.empty()) break;
int x = (*myset.begin());
myset.erase(myset.begin());
cnt++;
auto idx = myset.upper_bound(l-x);
if (idx==myset.begin()) continue;
idx--;
myset.erase(idx);
}
cout << cnt << endl;
}
return 0;
}
【习题 8-1 UVA - 1149】Bin Packing的更多相关文章
- UVA 1149 Bin Packing
传送门 A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the sa ...
- UVA 1149 Bin Packing 二分+贪心
A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the samele ...
- UVa 1149 Bin Packing 【贪心】
题意:给定n个物品的重量l[i],背包的容量为w,同时要求每个背包最多装两个物品,求至少要多少个背包才能装下所有的物品 和之前做的独木舟上的旅行一样,注意一下格式就好了 #include<ios ...
- uva 1149:Bin Packing(贪心)
题意:给定N物品的重量,背包容量M,一个背包最多放两个东西.问至少多少个背包. 思路:贪心,最大的和最小的放.如果这样都不行,那最大的一定孤独终生.否则,相伴而行. 代码: #include < ...
- UVA 1149 Bin Packing 装箱(贪心)
每次选最大的物品和最小的物品放一起,如果放不下,大物体孤独终生,否则相伴而行... 答案变得更优是因为两个物品一起放了,最大的物品是最难匹配的,如果和最小的都放不下的话,和其它匹配也一定放不下了. # ...
- UVA - 1149 Bin Packing(装箱)(贪心)
题意:给定N(N<=10^5)个物品的重量Li,背包的容量M,同时要求每个背包最多装两个物品.求至少要多少个背包才能装下所有的物品. 分析:先排序,从最重的开始装,如果重量小于M,则如果能装一个 ...
- UVa 102 - Ecological Bin Packing(规律,统计)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVa - 102 - Ecological Bin Packing
Background Bin packing, or the placement of objects of certain weights into different bins subject t ...
- Bin Packing
Bin Packing 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/F 题目: A set of ...
- Vector Bin Packing 华为讲座笔记
Vector bin packing:first fit / best fit / grasp 成本:性价比 (先验) 设计评价函数: evaluation function:cosine simil ...
随机推荐
- BZOJ 3786: 星系探索 欧拉游览树
一个叫 Euler-Tour-Tree 的数据结构,说白了就是用 Splay_Tree 维护欧拉序 #include <cstring> #include <algorithm> ...
- NodeJS学习笔记 (12)网络地址解析-url(ok)
模块概述 nodejs中,提供了url这个非常实用的模块,用来做URL的解析.在做node服务端的开发时会经常用到.使用很简单,总共只有3个方法. 正式讲解前,各位同学先把下面这个图记在心上(来自no ...
- 学习Go语言之简易ORM框架
ORM即为对象关系映射,ORM常用于程序适配多种数据库,以达到开放扩展关闭修改的原则.笔者初学Golang,遂有意写个简易ORM框架,权当知识巩固. 首先需要有一个思想就是数据库表结构都是固定,但是每 ...
- kolla-ansible 安装openstack 拉取阿里云镜像时报错
TASK [mariadb : Pulling mariadb image] ************************************************************ ...
- docker容器存放目录磁盘空间满了,转移数据修改Docker默认存储位置
原文:docker容器存放目录磁盘空间满了,转移数据修改Docker默认存储位置 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_3767485 ...
- X的追求道路
X的追求道路 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 X在大家的帮助下最终找到了一个妹纸,于是開始了漫漫的追求之路,那 ...
- Android中System.currentTimeMillis()
函数: System.currentTimeMillis(): 功能:产生一个当前的毫秒,这个毫秒事实上就是自1970年1月1日0时起的毫秒数,Date()事实上就是相当于Date(System.cu ...
- 99.重载[] * -> ->*
#include "mainwindow.h" #include <QApplication> #include <QPushButton>> //重 ...
- Python(六) Python 函数
一.认识函数 help(方法名字) help(round) 1.功能性 2.隐藏细节 3.避免编写重复的代码 4.组织代码 自定义函数 二.函数的定义及运行特点 # 递归 def sum_num(n ...
- React开发实时聊天招聘工具 -第二章
2-1 介绍React开发环境 npm install -g create-react-app xxx npm run eject 来配置webpack 2-2 ES6常用语法 其他 还有一些特性 ...