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的整数倍的点上分布着灯笼,而在 ...
随机推荐
- 关于integer overflow错误
前端突然报了integer overflow错误,int类型溢出也就是数字超过了int类型,一看很懵逼,查看后台日期发现是在Math.toIntExact()方法报错 那么我们看下方法内部代码: /* ...
- 开发RTSP 直播软件 H264 AAC 编码
上一篇对摄像头预览,拍照做了大概的介绍,现在已经可以拿到视频帧了,在加上 RTSP 实现,就是直播的雏形,当然还要加上一些 WEB 管理和手机平台的支援,就是一整套直播软件. 介绍一些基础概念:RTP ...
- centOS 6.5 yum升级 gcc4.8 然后又退回来4.4
CentOS 6.5 用了很多年了,一直舍不得省7 . 由于要用到 c++ 11 ,所以决定升级一下. 为了省事我选择用 yum 方式升级,结果最后还是不能用,差点搞坏,这是真机,重装麻烦了. get ...
- 使用ajax提交登录
引入jquery-1.10.2.js或者jquery-1.10.2.min.js 页面 <h3>后台系统登录</h3> <form name="MyForm&q ...
- go源码分析(一) 通过调试看go程序初始化过程
参考资料:Go 1.5 源码剖析 (书签版).pdf 编写go语言test.go package main import ( "fmt" ) func main(){ fmt.Pr ...
- JavaScript表单序列化的方法详解
本文介绍下,在javascript中实现表单序列化的方法,通过实例加深理解,有需要的朋友参考下吧. 在JavaScript中,可以利用表单字段的type属性,连同name和value属性一起实现对表单 ...
- 基于SIP协议的性能测试——奇林软件kylinPET
一.Sip协议简介: SIP(Session Initiation Protocol,会话初始协议)是由IETF(Internet Engineering Task Force,因特网工程任务组)制定 ...
- CSS每日学习笔记(1)
7.30.2019 1.CSS 文本属性 属性 描述 color 设置文本颜色 direction 设置文本方向. line-height 设置行高. letter-spacing 设置字符间距. t ...
- 4. selenium中鼠标和键盘操作
一.鼠标操作 第一步:引入模块函数 from selenium.webdriver.common.action_chains import ActionChains 第二步:元素定位 element ...
- linux入门系列18--Web服务之Apache服务2
接上一篇文章,在了解Apache基本配置以及SELinux相关知识后,继续演示Apache提供的虚拟主机功能以及访问控制方式. 如果还没看上一篇的建议先查看后再来,上篇文章"linux入门系 ...