https://vjudge.net/problem/UVA-1149 题意:给定N个物品的重量和背包的容量,同时要求每个背包最多装两个物品.求至少需要的背包数. 思路:很简单的贪心.每次将最轻的和最重的放一个背包里,如果放不下,则只放一个最重的. #include<iostream> #include<algorithm> using namespace std; + ; int n, m; int a[maxn]; int ans; void solve() { ans = ;…
传送门 A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the same length l and each item i has length li ≤ l. We look for a minimal number of bins q such that • each bin contains at most 2 items, • each item is pa…
题意:给定N物品的重量,背包容量M,一个背包最多放两个东西.问至少多少个背包. 思路:贪心,最大的和最小的放.如果这样都不行,那最大的一定孤独终生.否则,相伴而行. 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100100 int a[N]; int main() { int t; scanf("%d", &a…
A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the samelength l and each item i has length li ≤ l. We look for a minimal number of bins q such that• each bin contains at most 2 items,• each item is packed in…
排序之后, 尽量最小和最大的放在一个背包, 放不下就放最大的. #include<cstdio> #include<algorithm> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; const int MAXN = 112345; int a[MAXN]; int main() { int n, lmax; int T, kase = 0; scanf("%d&qu…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个背包只能装两个东西. 而且每个东西都要被装进去. 那么我们随意考虑某个物品.(不必要求顺序 这个物品肯定要放进某个背包里面的. 那么背包数递增. 那么剩余的空间. 只能装一个了. 要装谁呢? 肯定是尽可能装较大的.所以用upper_bound-1找一个最大的能装的装就可以了. 这样就能尽量减少体积较大的物品了. [代码] /* 1.Shoud it use long long ? 2.Have you ever test s…