UVA 1149 Bin packing
2015-09-01 20:40
232 查看
//重做这个题完全是为了使用res.erase();
以前比赛的时候基本不敢用, 事实证明是可以A题的;不能res.erase(res.end());
不知为何。。。
以前比赛的时候基本不敢用, 事实证明是可以A题的;不能res.erase(res.end());
不知为何。。。
#include<cstdio> #include<iostream> #include<vector> #include<cstring> #include<string.h> #include<algorithm> using namespace std; vector<int> res; int main() { int n; int W; int T; cin >>T; while(T--) { res.clear(); scanf("%d%d", &n, &W); for(int i = 0; i <n; ++i) { int t; scanf("%d", &t); res.push_back(t); } sort(res.begin(), res.end()); int cnt = 0; while(!res.empty()) { ++cnt; vector<int> :: iterator it = upper_bound(res.begin()+1, res.end(), W-res[0]) - 1; if(it != res.begin()) { res.erase(it);res.erase(res.begin());} else res.erase(res.begin()); } cout << cnt << endl; if(T) printf("\n"); } }
相关文章推荐
- ViewPager(页面滑动,加动态点,循环,加标题)
- 编写一个程序找出100~999之间所有的水仙花数
- GCC 编译详解 (转)
- 同时用两个定时器控制蜂鸣器发声,定时器0控制频率,定时器1控制同个频率持续的时间,间隔300ms依次输出1,10,50,100,200,400,800,1K的方波
- 【单链表】
- Android:Layout_weight的深刻理解
- 1094. The Largest Generation (25)
- mongodb创建用户操作
- 面试题24:二叉搜索树的后序遍历序列
- 关于Oracle GoldenGate 参数TRANLOGOPTIONS altarchivelogdest
- 判断两个字符串是否由相同的字符组成
- js跨域请求简单例子
- Objective-C之Mark
- iOS学习--UIWebView
- 快速排序
- MAC OS X上安装Docker
- Zepto.js touch模块深入分析 解决手机点击事件
- Android-调用本地方法传递数组参数/NDK-JNI开发实例(五)
- Android listView的应用以及Activity跳转
- leetcode:twosum