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的整数倍的点上分布着灯笼,而在 ...
随机推荐
- 钉钉小程序不用canvas在后端绘图前端用image标签获取图片的实践
公司的需求要用电子员工卡代替用了N久的工作证,在各种场合刷二维码来代替刷卡.在钉钉小程序里实现.感觉这回又要躺坑里了. 钉钉小程序第一次做.我这个自封的GDI+大神才不要想用钉钉jsapi的方式用ca ...
- 2019年最新老男孩高性能Web架构与自动化运维架构视频教程
课程目录L001-老男孩架构15期-Web架构之单机时代L002-老男孩架构15期-Web架构之集群时代L003-老男孩架构15期-Web架构之dnsL004-老男孩架构15期-Web架构之缓存体系L ...
- SpringBoot1.5.10.RELEASE整合druid
1.先在pom文件中导入druid的jar包 <dependency> <groupId>com.alibaba</groupId> <artifactId& ...
- 微信WXSS样式文件
目录 WXSS官方文档 1. WXSS 1.1. 尺寸单位 1.2. 样式导入 1.3. 内联样式 1.4. 选择器 1.5. 全局样式与局部样式 WXSS官方文档 https://developer ...
- SpringBoot框架——从SpringBoot看IoC容器初始化流程之方法分析
目录 一.概观Spring Boot 二.Spring Boot应用初始化 2.1 初始化入口 2.2 SpringApplication的run方法 2.3 方法分析 三.容器创建与初始化 3.1 ...
- flask 模型一对多个人理解
在modle中创建两个模型表 class User(db.Model): id = db.Column(db.Integer,primary_key=True,autoincrement=True) ...
- opt目录
在linux环境测试时,会部署到/opt目录下,这是为何呢? 下面来详解Linux的/opt目录: /opt:用户级的程序目录 这里主要存放那些可选的程序. 比如,你想部署firefox测试版,那就装 ...
- echarts-liquidfill 水球显示小数点
使用echarts-liquidfill.js的水球,水球上显示的文字可以使用chartOption.series[0].label.normal.formatter设置,想显示什么显示什么. var ...
- MVC项目中存储公用链接方法
小白成长记第一篇,随手记录一下小常识 将固定地址写在web.config文件appSettings中 Controller调用方法:
- SQL语句中,如何使用含有if....else...判断语句
在我们开发中,有时要对数据库中的数据按照条件进行查询,用到if else类似的语句进行判断,那么if else语句只有在存储过程,触发器之类的才有,但是要在sql上当满足某种条件上要取不同的字段值,刚 ...