您的位置:首页 > 其它

UVa 11100 - The Trip, 2007

2015-12-16 15:08 316 查看
題目:給你一些箱子,相對小的箱子和以放進大箱子,問最少剩下幾個箱子,並且每個箱子裝的盡量少。

分析:貪心,數論。排序,出現次數最多的那個數字就是剩下的箱子個數d。

題目要求每個箱子裝的盡量少,就是要裝的平均的意思,這裡將排序后的箱子等距離d輸出即可;

(距離d可以保證每個必不相同,因為任意兩個相同的數字間的差必小於d);

說明:╮(╯▽╰)╭。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int data[10001];

int main()
{
	int n, t = 0;
	while (~scanf("%d",&n) && n) {
		for (int i = 0; i < n; ++ i)
			scanf("%d",&data[i]);
		sort(data, data+n);
		
		int count = 1, max = 1;
		for (int i = 1; i < n; ++ i) {
			if (data[i] != data[i-1])
				count = 1;
			else count ++;
			if (max < count)
				max = count;
		}
		
		if (t ++) printf("\n");
		printf("%d\n",max);
		for (int i = 0; i < max; ++ i) {
			for (int j = i; j < n; j += max) {
				if (j >= max) printf(" ");
				printf("%d",data[j]);
			}
			printf("\n");
		}
	} 
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: