Boxes Packing
Boxes Packing
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a
cube with side length ai.Mishka can put a box i into another box j if the following conditions
are met:i-th box is not put into another box; j-th box doesn’t contain any
other boxes; box i is smaller than box j (ai < aj). Mishka can put
boxes into each other an arbitrary number of times. He wants to
minimize the number of visible boxes. A box is called visible iff it
is not put into some another box.Help Mishka to determine the minimum possible number of visible boxes!
Input The first line contains one integer n (1 ≤ n ≤ 5000) — the
number of boxes Mishka has got.The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109),
where ai is the side length of i-th box.Output Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note In the first example it is possible to put box 1 into box 2, and
2 into 3.In the second example Mishka can put box 2 into box 3, and box 4 into
box 1.
思路如下
- 题意:n个盒子,大盒子可以套到小盒子外边(前提是大盒子里面不能 有其它盒子),问当大盒子套小盒子,之后最后还剩下几个盒子能被看到
- 思路:在 n 个 盒子的边长中找出现次数最多的边长,该边长就是答案
题解如下
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int ar[n + 5];
for(int i = 0; i < n; i ++)
scanf("%d", &ar[i]);
sort(ar, ar + n);
int i,j;
int res = -1;
for(i = n - 1; i >=0 ; i --) //找出那条边出现现次数最多
{
int ans = 1;
for(j = i - 1; j >= 0; j --)
{
if(ar[i] == ar[j])
ans ++;
else
{
i = j + 1;
break;
}
}
res = max(res , ans);
}
printf("%d",res);
return 0;
}
Boxes Packing的更多相关文章
- Educational Codeforces Round 34 (Rated for Div. 2) C. Boxes Packing
C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Educational Codeforces Round 34 C. Boxes Packing【模拟/STL-map/俄罗斯套娃】
C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CodeForces Round #515 Div.3 D. Boxes Packing
http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size e ...
- D. Boxes Packing
链接 [http://codeforces.com/contest/1066/problem/D] 题意 题目大意 n个物品m个篮子每个篮子容量为k 每个物品重量为a[i] 问能装多少物品 这个人是强 ...
- CF1066D Boxes Packing
传送门 这题为什么要用二分呢?/huaji 首先可以\(O(n)\)预处理出从某个物品\(i\)开始放,只放一个盒子,能放的最后物品的位置\(j\),只要用两个指针维护左右端点,每次移动一下左端点同时 ...
- CF1066D Boxes Packing(二分答案)
题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$.$Maksim$先生想把物品装入盒子中.对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个 ...
- 903C. Boxes Packing#俄罗斯套娃问题(map使用)
题目出处:http://codeforces.com/problemset/problem/903/C 题目大意:求这组数据中数据出现的最大重复次数 #include<iostream> ...
- Codeforces Round #515 (Div. 3)
Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...
- Codeforces Round #515 (Div. 3) 解题报告(A~E)
题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...
随机推荐
- Idea安装教程以及环境变量配置
IDEA安装以及JDK环境变量 环境变量配置 下载jdk
- Simulink仿真入门到精通(七) Simulink的回调函数
7.1 什么是回调函数 Callback functions(回调函数)是因某种操作而除法对其调用的函数,如按下按钮或双击操作等. 常用的Simulink回调函数可应用在以下场合: 打开Simulin ...
- 【tomcat系列】详解tomcat架构(上篇)
java中,常用的web服务器一般由tomcat,weblogic,jetty,undertwo等,但从用户使用广泛度来说,tomcat用户量相对比较大一些,当然这也基于它开源和免费的特点. 从软件架 ...
- Jenkins+Ant+JMeter集成
Tomcat是jenkins运行的容器,jenkins实际上是依赖于Tomcat才能启动的.Jenkins可以调度ant的脚本. Ant和maven类似,maven是执行pom文件,ant是执行bui ...
- Swift 4.0 数组(Array)学习
定义数组常量(常量只有读操作) let array1: [Int] = [11, 55, 5] let array2 = [11, 55, 5] 定义数组变量 var array: [Int] = [ ...
- iOS 指纹认证登陆开发(TouchID)
设计思路 TouchID 关联账号 用户登陆成功 -> 开启TouchID登陆 -> TouchID验证 -> 记录用户信息(验证通过) -> 关联完成 TouchID 登陆 ...
- 零售CRM系统开发的核心功能
在零售行业中,客户关系管理系统是一个包含销售,市场营销和客户服务流程的中央枢纽.它为企业所有者提供了一种可以结合所有与销售有关的问题并管理销售流程的有效工具.零售CRM可以留住客户,提供个性化的一流客 ...
- mysql查询性能问题,加了order by速度慢了
关于order by的查询优化可以看一下: MySQL ORDER BY/LIMIT performance: late row lookups 主要介绍了两个方法: 第一个是FORCE INDEX ...
- 常用正则表达式(手机号、邮箱、URL地址、身份证等等)
一.前言 不好的习惯:1.每一次用到正则都是上网copy一份,也没有去学习思考,看看都是什么意思: 2.一个项目里不同的地方用到了相同的校验,一直在重复的copy代码,并没有统一起来,万一哪天要修改规 ...
- jvm:内存结构(堆、方法区、程序计数器、本地方法栈、虚拟机栈)
1.jvm内存结构 静态编译:把java源文件编译成字节码文件class,这个时候class文件以静态方式存在. 类加载器:把java字节码文件加载到内存中 方法区:将字节码放到方法区作为元数据(简单 ...