UVa 1149 Bin Packing (二分 + 贪心)
来源:互联网 发布:苹果清除缓存软件 编辑:程序博客网 时间:2024/06/13 21:59
UVA 第一次用 不会用, 输出错误 竟然 发邮箱 , 好贴心的操作
贪心, 按照从小 到大排序, 然后 二分背包数目, 因为 背包 最大就是 n
所以
#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <math.h>#include <cstring>#include <string>#include <queue>#include <stack>#include <stdlib.h>#include <list>#include <map>#include <set>#include <bitset>#include <vector>#define mem(a,b) memset(a,b,sizeof(a))#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w",stdout)#define S1(n) scanf("%d",&n)#define SL1(n) scanf("%I64d",&n)#define S2(n,m) scanf("%d%d",&n,&m)#define SL2(n,m) scanf("%I64d%I64d",&n,&m)#define Pr(n) printf("%d\n",n)using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int MOD=1e9+7;const int mod=1e9+7;int dir[5][2]={0,1,0,-1,1,0,-1,0};int a[maxn];int b[maxn];int n;int L;int judge(int x){ int k=1; mem(b,0); for(int i=n;i>=n-x+1;i--) b[k++]=a[i]; k--; for(int i=n-x;i>=1;i--) { if(a[i]+b[k--]>L) return 1; } return 0;}int main(){ int t; cin>>t; while(t--) { cin>>n; mem(a,0); cin>>L; for(int i=1;i<=n;i++) { S1(a[i]); } sort(a+1,a+n+1); int l=1,r=n; while(r-l>1) { int mid=(l+r)>>1; if(judge(mid)) l=mid; else r=mid; } printf("%d\n",r); if(t>0) printf("\n"); } return 0;}
123
阅读全文
0 0
- UVa 1149 Bin Packing (二分 + 贪心)
- UVa 1149 - Bin Packing [贪心]
- UVA 1149 Bin Packing(贪心)
- UVa 1149 - Bin Packing(贪心+二分查找)
- UVA 1149 - Bin Packing ( 贪心 + 二分 & STL )
- uva 1149 Bin Packing 装箱 (二分+贪心)
- 【uva】1149-Bin Packing(贪心 + STL )
- UVA - 1149 Bin Packing 贪心水题
- UVA 1149 bin packing (贪心)
- UVA 1149 Bin Packing 装箱(简单贪心)
- uva 1149 Bin Packing(贪心)
- Uva - 1149 - Bin Packing
- UVA 1149 - Bin Packing
- UVA 1149 Bin Packing
- uva 1149Bin Packing
- UVA 1149 Bin packing
- UVA 1149 Bin Packing
- UVA - 1149 Bin Packing
- 食物链 POJ
- jQuery鼠标随意移动div
- 洛谷P1445:没占到1444的愤怒 (数学推导+线性筛)
- struts.xml中extends="struts-default"报错
- 如何禁用 Azure 虚拟机的日期时间同步
- UVa 1149 Bin Packing (二分 + 贪心)
- Linux HGDB执行pg_ctl start或stop时显示?解决办法
- 多用户多分组的SFTP配置方式(FTP over SSH)
- 程序员江湖鄙视链大全,看看你处于链条的哪一级?
- 开源框架PullToRefresh、PinnedHeaderListView、PhotoView、CustomShapeImageView
- 清除eclipse当前登录的svn账户
- 查看锁表进程和杀死锁
- Python3网络爬虫:使用Beautiful Soup爬取小说
- Pytorch入门——安装