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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. D. Boxes Packing

    链接 [http://codeforces.com/contest/1066/problem/D] 题意 题目大意 n个物品m个篮子每个篮子容量为k 每个物品重量为a[i] 问能装多少物品 这个人是强 ...

  5. CF1066D Boxes Packing

    传送门 这题为什么要用二分呢?/huaji 首先可以\(O(n)\)预处理出从某个物品\(i\)开始放,只放一个盒子,能放的最后物品的位置\(j\),只要用两个指针维护左右端点,每次移动一下左端点同时 ...

  6. CF1066D Boxes Packing(二分答案)

    题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$.$Maksim$先生想把物品装入盒子中.对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个 ...

  7. 903C. Boxes Packing#俄罗斯套娃问题(map使用)

    题目出处:http://codeforces.com/problemset/problem/903/C 题目大意:求这组数据中数据出现的最大重复次数 #include<iostream> ...

  8. Codeforces Round #515 (Div. 3)

    Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...

  9. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

随机推荐

  1. 2018-05-04 圣杯布局 and 双飞翼布局,display:flex

    看到一个神奇的布局,啥都不说了 直接贴代码 要让main在中间,left在左边,可以通过Flex容器下的项目的属性“order”属性来设置:对于order属性:定义项目的排列顺序,越小越靠前,默认为0 ...

  2. 作为一个Tester,你在客户环境能保证质量吗?

    公司严格地按照“产品-项目”模式来架构技术部门. 我又测产品,又测项目,所以一方面可以从项目测试的角度发现产品bug,并且给产品提供改进意见,一方面还能测产品为项目赋能,保证项目质量,让项目经理轻松些 ...

  3. 用libvlc 播放指定缓冲区中的视频流

    有时候,我们需要播放别的模块传输过来的视频流,VLC提供了这样的机制,但一般很少这样用,下面的例子实现了这样的功能. 其中用到一个关键的模块 imem.  vlc提供多种创建媒体的方式,如要从指定缓存 ...

  4. CSRF攻击原理及预防手段

      CSRF全程 Cross Site Request Forgery, 跨站域请求伪造.这种攻击方式相对于XSS,SQL注入等攻击方式比较晚被发现,今天就来讲解下这种攻击方式以及避免方式. 攻击过程 ...

  5. mongo密码的设置

    MongoDB 版本 v4.0.7 系统 Win10 注意: 要为数据库创建用户,必须先切换到相应的数据库: 要为数据库创建用户,必须先切换到相应的数据库: 要为数据库创建用户,必须先切换到相应的数据 ...

  6. 基于 HTML5 WebGL 的发动机 3D 可视化系统

    前言     工业机械产品大多体积庞大.运输成本高,在参加行业展会或向海外客户销售时,如果没有实物展示,仅凭静态.简单的图片说明书介绍,无法让客户全面了解产品,不仅工作人员制作麻烦,客户看得也费力.如 ...

  7. 深入理解requestAnimationFrame并实现相册组件中的切换动画

    全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/12529885.html,多谢,=.=~ (如果对你有帮助的话请帮我点个赞啦) 通常情况下,我们利 ...

  8. 如何查看子线程中的GC Alloc

    1)如何查看子线程中的GC Alloc2)Build时,提示安卓NDK异常3)如何获得ParticleSystem产生的三角形数量4)关于图片通道的问题5)GPUSkinning导致模型动画不平滑 M ...

  9. Google Sign In

    我们平常也经常使用QQ,微信账号,登录其他应用.最近公司让我给网站添加一个谷歌账号登录.我来这里记录一下,莫怪~~~莫怪~~~ 1. 申请一个账号登录ID:  https://developers.g ...

  10. 大数据软件安装之Hive(查询)

    一.安装及配置 官方文档: https://cwiki.apache.org/confluence/display/Hive/GettingStarted 安装Hive2.3 1)上传apache-h ...