UVa 11100 - The Trip, 2007
2015-12-16 15:08
316 查看
題目:給你一些箱子,相對小的箱子和以放進大箱子,問最少剩下幾個箱子,並且每個箱子裝的盡量少。
分析:貪心,數論。排序,出現次數最多的那個數字就是剩下的箱子個數d。
題目要求每個箱子裝的盡量少,就是要裝的平均的意思,這裡將排序后的箱子等距離d輸出即可;
(距離d可以保證每個必不相同,因為任意兩個相同的數字間的差必小於d);
說明:╮(╯▽╰)╭。
分析:貪心,數論。排序,出現次數最多的那個數字就是剩下的箱子個數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; }
相关文章推荐
- Mac 上安装app,提示“***已损坏,打不开。您应该将它移到废纸篓。”解决方案
- [转]Android中时间和时区的自动更新(NITZ+ZONE)
- C#支付宝移动支付开发详细教程
- JavaScript DOM 编程艺术 学习笔记(1)(从零学javascript)
- asp.net 计算两个时间差
- 重写 onCreateOptionsMenu(Menu menu) 方法,却不执行。
- 学网站设计有感一
- CDH5.5.0中配置运行Spark SQL的Thrift Server
- OC中的数组操作2
- JS中获取和操作iframe
- ?
- Storm并行度理解
- spring中bean的基本xml配置
- 微信企业号开发八:JSAPI模式之身份验证接口
- 【js小方法】isNaN,input中判断是数字
- windows下安装mongodb扩展出现 PHP Warning: PHP Startup: in Unknown on line 0
- HYSBZ 1053 反质数
- 类的特性
- SQL Server——存储过程
- 常用加密方式