问题描述:

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:

6
1 1 2 2 2 3
0

SAMPLEOUTPUT:

3
1 2
1 2
3 2

思路:

有一堆袋子,小的可以装到大的里面,同样大小的没有办法进行操作,问我们如何装能够用最小的组合装完所有的袋子。先在输入时确定每个大小的袋子数cont,显然最大的那个数量就是我们所需要的组合数(应该大家都懂吧)那就从最小的袋子开始取,每次的间隔为cont(这样能够确保不会出现相同大小的袋子在同一组中)一共取n组(肯定可以取完,但每组的数量是不一样的)

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{int n,a,num[10005], sum[10005],cont=0,i,j;while (scanf("%d",&n)&&n!=0){memset(num,0,sizeof(num));memset(sum,0,sizeof(sum));cont=0;for (i=0;i<n;i++){cin>>sum[i];num[sum[i]]++;cont=max(cont,num[sum[i]]);}cout<<cont<<endl;sort(sum,sum+n);for (i=0;i<cont;i++){for (j=i;j<n;j+=cont){cout<<sum[j];if (j+cont<n){cout<<' ';}else{cout<<endl;}}}}return 0;
}

POJ - 3287 The Trip, 2007相关推荐

  1. c语言编辑87152,POJ 3287 (基础BFS) Catch That Cow

    这是做的第一道BFS,很基础很简单的题目 广度优先搜索算法如下:(用QUEUE) (1) 把初始节点S0放入Open表中: (2) 如果Open表为空,则问题无解,失败 退出: (3) 把Open表的 ...

  2. POJ 3287 Catch That Cow(bfs)

          看懂意思就很简单了,给你一个数,每次只能加一或者减一或者乘2,问最少几次才能变成另一个数,就是一个简单的bfs过程,看代码吧. AC代码: #include <iostream> ...

  3. UVa11100 The Trip,2007(贪心)

    问题:给出n个包裹,小包裹可以放到大包裹里,问最小的包裹数,并且输出包裹里所包含的包裹 思路:包裹从小到大排序,统计尺寸包裹的个数,求得最大值.这个最大值就是最终的最小包裹数. 具体代码参考: htt ...

  4. POJ - 1734 Sightseeing trip(最小环+输出路径)

    题目链接:点击查看 题目大意:给定一张无向图,求图中至少一个包含三个点的环,环上的节点不重复,并且环上的边的长度之和最小.该问题称为无向图的最小环问题.在本题中,你需要输出最小环的方案,若最小环不唯一 ...

  5. UVA 11100 The Trip, 2007

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. poj 1734 Sightseeing trip(floyd 拓展 求最小环)

    对于floyd 拓展为什么可以判断 出最小环还是不是太理解 苟且 先贴下模版吧 感谢:心_随_梦_翔 的分析 http://hi.baidu.com/%D0%C4_%CB%E6_%C3%CE_%CF% ...

  7. POJ 1734 Sightseeing trip(Floyd)

    题目传送门 题目中文翻译: Description 桑给巴尔岛上的阿德尔顿镇有一家旅行社,它已决定为其客户提供除了许多其他名胜之外的景点.为了尽可能地从景点赚取收入,该机构已经接受了一个精明的决定:有 ...

  8. POJ 计算几何入门题目推荐

      其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专 ...

  9. poj计算几何题推荐

    POJ 计算几何入门题目推荐(转)       其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的 ...

最新文章

  1. 机器学习中的数学意义
  2. 随行付微服务测试之静态代码扫描
  3. “达克效应”让人们信心满满还是畏惧不前?- 更应该是谨慎地冒险
  4. Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference
  5. 一文看懂Python多进程与多线程编程(工作学习面试必读)
  6. 科大星云诗社动态20210210
  7. UI framework 处理user 错误输入的逻辑
  8. Protocol Buffer 序列化
  9. oracle sum详解,oracle sum()聚合函数
  10. Linq to Oracle 使用教程(七)将数据库的存储过程映射到方法
  11. oracle内置函数 trunc 使用
  12. r 选取从小到大的数据_玩点特别的!AI打造可编辑数据图表!
  13. 04.electron-(使用remove模块及安全策略)
  14. 通过WDS功能扩大无线网范围
  15. 个人主页 — github + jekyll 搭建自己的个人主页
  16. 三、字符串拼接和占位符
  17. Android自定义WebView实现Youtube网络视频播放控件
  18. 计算机专业对口大学,计算机专业对口升学有哪些大学
  19. Oracle与SQL *PLUS简介
  20. python分行输入_python换行输入

热门文章

  1. linux下安装部署apollo(详细步骤)
  2. Maven项目POM配置好后,下载jar包位置设置(本地仓库配置)
  3. 58 Three.js 通过THREE.Raycaster给模型绑定点击事件
  4. 《数字图像处理》学习总结及感悟:第二章数字图像基础(2)电磁波、传感器及辐射成像原理
  5. 27款开源图片相册管理系统
  6. SpringzCloud之Feign原理
  7. 学习加密(四)spring boot 使用RSA+AES混合加密,前后端传递参数加解密
  8. Docear放大字体
  9. Leetcode 517. Super Washing Machines [Python]
  10. Java+微信公众号开发学习总结(一)