简单地贪心。。。。先排序,然后看最小的a和最大的b能否在同一条船上,若不能,则船数加1,b--;若能则 a++ , b--,ans++ ;
//
// main.cpp
// uva 1149 - Bin Packing
//
// Created by XD on 15/8/15.
// Copyright (c) 2015年 XD. All rights reserved.
//
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<vector>
#include <string.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstdio>
using namespace std ;
const int maxn = 100000 + 5;
int bin[maxn] ;
int main(int argc, const char * argv[]) {
int n ,ans,l,T;scanf("%d" ,&T) ;
int flag = 1 ;
while (T--) {
if (!flag) {
printf("\n") ;
}flag = 0 ;
scanf("%d%d" ,&n,&l) ;
for (int i = 0; i < n ; i++) {
scanf("%d" ,&bin[i]) ;
}
sort(bin, bin + n ) ;
int x=0 , y = n-1 ;
ans =0 ;
while (x <=y) {
if (x == y ) {
ans++ ; break ;
}
int tl = bin[x] + bin[y] ;
if (tl<=l) {
ans++ ; x++ ; y-- ;
}
else if(tl > l )
{
ans++ ; y-- ;
}
}
printf("%d\n" , ans) ;
}
return 0;
}