UVa 11100 - The Trip, 2007
2013-08-21 19:59
369 查看
题目大意:有n个包,其中小包可以装到大的包里,包的大小用数字进行表示,求最小的装包数量。
统计每个数字出现的次数,其中次数的最大值k就是最小的装包数量。答案显然不可能比k小,而把相同大小的包装进不同的大包里显然满足条件。题目中有一句话纠结了半天,“While maintaining the minimal number of pieces you are also to minimize the total number of bags in any one piece that must be carried.” 大概是说让每个大包里的小包的数量的最大值最小吧,也就是要把小包尽可能平均放到这k个大包里,于是就有了有了“排序,以k为等差的序列”这一解法,因为a[i+k] > a[i]。
View Code
统计每个数字出现的次数,其中次数的最大值k就是最小的装包数量。答案显然不可能比k小,而把相同大小的包装进不同的大包里显然满足条件。题目中有一句话纠结了半天,“While maintaining the minimal number of pieces you are also to minimize the total number of bags in any one piece that must be carried.” 大概是说让每个大包里的小包的数量的最大值最小吧,也就是要把小包尽可能平均放到这k个大包里,于是就有了有了“排序,以k为等差的序列”这一解法,因为a[i+k] > a[i]。
#include <cstdio> #include <algorithm> using namespace std; #define MAXN 10000+10 int a[MAXN]; int main() { #ifdef LOCAL freopen("in", "r", stdin); #endif int n; bool first = true; while (scanf("%d", &n) != EOF && n) { for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a+n); int k = 1, cnt = 1; for (int i = 1; i <= n; i++) { if (i == n || a[i] != a[i-1]) { if (cnt > k) k = cnt; cnt = 1; } else cnt++; } if (first) first = false; else printf("\n"); printf("%d\n", k); for (int i = 0; i < k; i++) { for (int j = i; j < n; j += k) printf("%s%d", (i==j) ? "" : " ", a[j]); printf("\n"); } } return 0; }
View Code
相关文章推荐
- UVA 11100 The Trip, 2007
- uva11100 - The Trip, 2007
- uva 11100 The Trip, 2007
- uva - 11100 - The Trip, 2007(贪心)
- UVA 11100 The Trip, 2007——水题
- UVa11100 - The Trip, 2007(贪心【重点:解的构造)
- UVA 11100 The Trip, 2007
- UVA11100 The Trip, 2007(贪心)
- UVa 11100 The Trip, 2007 (题意+贪心)
- uva 11100 The Trip, 2007
- UVA 11100 - The Trip, 2007
- uva 11100 The Trip, 2007
- UVA - 11100 The Trip, 2007
- UVA 11100 The Trip,2007(贪心)
- [贪心]UVA11100 - The Trip, 2007
- 旅行 The Trip, 2007 UVA - 11100 构造&输出技巧
- UVA 11100 - The Trip, 2007(贪心)
- UVA 11100 The Trip, 2007 贪心(输出比较奇葩)
- UVa 11100 - The Trip, 2007
- UVA 11100 The Trip, 2007