1149
来源:互联网 发布:各国经济数据 编辑:程序博客网 时间:2024/06/06 03:03
UVA-1149:
题目大意:给定n个物品的重量,无限个容量为m的箱子,每个箱子最多装两个物品,要把所有的物品都装下,最少需要多少个箱子
题目分析:贪心策略:每次将最重和最轻的两个物品放到一个箱子里,如果装不下,则将最重的单独装到一个箱子里。
点击打开链接
#include <bits/stdc++.h>using namespace std;int main(){ int n; cin>>n; while(n--){ int l,m,a[100005]; cin>>m>>l; for(int i=0;i<m;i++){ cin>>a[i]; } sort(a,a+m); int cnt=0,mm=m-1,i=0; while(i<=mm){ if(a[i]+a[mm]<=l) i++; cnt++;mm--; } cout<<cnt<<endl; if(n) cout<<endl; } return 0;}
0 0
- 1149
- 1149
- problem 1149
- 1149 PIGS
- sicily 1149
- poj 1149
- 1149 PIGS
- POJ 1149
- POJ-1149
- POJ 1149
- ZOJ-1149
- poj 1149
- UVA 1149
- POJ 1149
- poj 1149
- POJ 1149
- ural 1149
- 洛谷1149
- 登录超时重新登录
- 吃糖果
- JSON中result的root属性
- Python tips: 什么是*args和**kwargs?
- Problem
- 1149
- c#
- HTC VIVE 发射线
- Python+Selenium框架设计篇之4-框架内封装日志类和浏览器引擎类
- Linux Centos7.3 开机启动 Redis 服务
- java - 泛型程序设计(二)
- Return code of 127 for check of host 'test1' was out of bounds. Make sure the plugin you're trying t
- HTTP深入浅出 http请求
- 点击图片放大、获取图片地址和显示阴影demo