UVaOJ11100 - The Trip, 2007
来源:互联网 发布:数据库密码 编辑:程序博客网 时间:2024/04/28 14:07
Problem A: The Trip, 2007
A number of students are members of a club that travels annually to exotic locations. Their destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, Atlanta, Eindhoven, Orlando, Vancouver, Honolulu, Beverly Hills, Prague, Shanghai, and San Antonio. This spring they are hoping to make a similar trip but aren't quite sure where or when.An issue with the trip is that their very generous sponsors always give them various knapsacks and other carrying bags that they must pack for their trip home. As the airline allows only so many pieces of luggage, they decide to pool their gifts and to pack one bag within another so as to minimize the total number of pieces they must carry.
The bags are all exactly the same shape and differ only in their linear dimension which is a positive integer not exceeding 1000000. A bag with smaller dimension will fit in one with larger dimension. You are to compute which bags to pack within which others so as to minimize the overall number of pieces of luggage (i.e. the number of outermost bags). 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.
Standard input contains several test cases. Each test case consists of an integer 1 ≤ n ≤ 10000 giving the number of bags followed by n integers on one or more lines, each giving the dimension of a piece. A line containing 0 follows the last test case. For each test case your output should consist of k, the minimum number of pieces, followed by k lines, each giving the dimensions of the bags comprising one piece, separated by spaces. Each dimension in the input should appear exactly once in the output, and the bags in each piece must fit nested one within another. If there is more than one solution, any will do. Output an empty line between cases.
Sample Input
61 1 2 2 2 30
Output for Sample Input
31 21 23 2
Troy Vasiga, Graeme Kemkes, Ian Munro, Gordon V. Cormack
#include <iostream>#include <algorithm>#include <vector>#include <cstdio>using namespace std;const int MAXN = 10001;int arr[MAXN], N;void input() { for (int i = 0; i < N; i ++) { scanf("%d", &arr[i]); } sort(arr, arr + N);}void solve() { int cur = 0, n = 0; vector<int> b[MAXN]; while (cur < N) { int pre = cur; while (cur < N && arr[cur] == arr[pre]) cur ++; n = max(n, cur - pre); } for (int i = 0; i < N; i ++) { b[i % n].push_back(arr[i]); } printf("%d\n", n); for (int i = 0; i < n; i ++) { printf("%d", b[i][0]); for (int j = 1; j < b[i].size(); j ++) { printf(" %d", b[i][j]); } printf("\n"); }}int main() { int t = 0; while(scanf("%d", &N) != EOF && N) { input(); if (t ++) printf("\n"); solve(); } return 0;}
- UVaOJ11100 - The Trip, 2007
- The Trip. 2007
- 11100 - The Trip, 2007
- uva11100 - The Trip, 2007
- UVA11100- The Trip, 2007
- The Trip, 2007
- uva11100 - The Trip, 2007
- The Trip, 2007 UVA
- The Trip, 2007 UVA
- 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
- POJ-3287-The Trip, 2007
- UVA 11100 - The Trip, 2007
- UVA 111000 The Trip, 2007
- UVaOJ10720 - Graph Construction
- UVaOJ10716 - Evil Straw Warts Live
- 自动化测试框架思想与构建【转载内容】
- Qt实现系统的开机启动
- 软件之美: 易用性设计的目标及准则
- UVaOJ11100 - The Trip, 2007
- UVaOJ10245 - The Closest Pair Problem
- Java基础知识 (扫盲)
- c++中的int和float存储编码方法
- UVaOJ11129 - An antiarithmetic permutation
- SVN操作概述
- 不同过插件使用 linksalpha 同步wp内容到社交网络的方法
- 直接拿来用!最火的Android开源项目(完结篇)
- vb.net向acces数据库添加记录,怎么用代码实现?