uva 11100- The Trip
来源:互联网 发布:淘宝咸鱼拍卖网 编辑:程序博客网 时间:2024/06/06 14:26
11100 - The Trip, 2007
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=2041
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 integer1 ≤ n ≤ 10000 giving the number of bags followed byn 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
题目大意:有 n 个包,大包可以装一个小包,问这些包能组成的最少包数,且要把不相同的放在一起;
题解: 找出 n 个数中出现最多次数的数看,即形成的最少包数,从小到大排序,序后,间隔k输出即可,因为k是出现最多的数,所以每隔k个输出保证不会相同,同时每组包的数目又最小。
例如:
1122334444556666 可以分成 1346,1346,2456 2456四个,即 k =4;
代码:
#include<iostream>#include<cstring>#include<algorithm>using namespace std;int a[10010],b[10010];int main(){ int n; while(cin>>n&&n) { memset(b,0,sizeof(b)); for(int i=0;i<n;i++) { cin>>a[i]; b[a[i]]++; } int maxn=b[0]; for(int i=0;i<10010;i++) { maxn=max(maxn,b[i]); } cout<<maxn<<endl; sort(a,a+n); for(int i=0;i<maxn;i++) { cout<<a[i]; for(int j=i+maxn;j<n;j+=maxn) cout<<" "<<a[j]; cout<<endl; } cout<<endl; }}
- UVA 11100 The Trip
- uva 11100 The trip
- Uva 11100 The Trip
- UVa 11100 The Trip
- uva 11100- The Trip
- 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
- 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
- uva--11100The Trip, 2007
- DTW算法
- 关于Retrofit2的两种拦截器
- 原理总结-springmvc
- 使用gradle 创建springboot项目
- 小白公司遇难记(2)
- uva 11100- The Trip
- 从oracle官网下载JavaMail所需jar的操作流程
- 看图理解JWT如何用于单点登录
- 登录失败次数限制(原生php代码实现)
- input radio按钮点击选择,点击另外一个,前一个不被选择
- 网络管理(十二)
- golang 常量的iota使用
- ASP.NET Core Razor页面 vs MVC
- Storm消费kafka写入华为云Hbase