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. Cake URAL - 1755

    1755. Cake Time limit: 0.5 secondMemory limit: 64 MB Karlsson and Little Boy have found a cake in th ...

  2. java编写非对称加密,解密,公钥加密,私钥解密,RSA,rsa

    非对称加密已经被评为加密标准,主要包含(公钥加密私钥解密,或者私钥加密公钥解密)本文主要讲解的是如何用java生成 公钥和私钥并且 进行字符串加密 和字符串解密    //如需要代码copy如下 im ...

  3. python如何用format进行进制转换与如何删除进制前缀

    10进行十进制,十六进制,八进制,二进制的转换:(#:保留进制前缀)对于带着进制前缀的,如"0x"“0o”“0b”,可以直接在后面加上’x’‘o’'b’进行删除:其他的一些小技巧: ...

  4. git密令使用

    git密令是一种非常好用的代码版本管理工具,相比SVN,Sourcetree 使用起来复杂,主要是没有汉化包,当你使用熟练时,其实也是非常简单的,逼格高. 具体使用如下: 情景一:你只有远程库,没有本 ...

  5. python3.4.3 调用http接口 解析response xml后插入数据库

    工作中需要调用一个http的接口,等不及java组开发,就试着用python去调用.Python版本3.4.3 完整的流程包括:从sqlServer取待调用的合同列表 -> 循环调用http接口 ...

  6. 详解如何快速使用数据可视化BI软件创建医疗运营监控数据中心大屏

    灯果数据可视化BI软件是新一代人工智能数据可视化大屏软件,内置丰富的大屏模板,可视化编辑操作,无需任何经验就可以创建属于你自己的大屏.大家可以在他们的官网下载软件.   本文以医疗运营监控数据中心大屏 ...

  7. 我用STM32MP1做了个疫情监控平台3—疫情监控平台实现

    目录 1.前言 2.数据接口的获取 3.Qt界面的实现 4.在开发板上运行Qt程序 5.使用无线模块联网 6.代码下载 @ 1.前言 之前我使用桌面版本Qt实现了肺炎疫情监控平台:基于Qt的新冠肺炎疫 ...

  8. 不要再认为Stream可读性不高了!

    距离Java 8发布已经过去了7.8年的时间,Java 14也刚刚发布.Java 8中关于函数式编程和新增的Stream流API至今饱受"争议". 如果你不曾使用Stream流,那 ...

  9. MySQL笔记(5)-- SQL执行流程,MySQL体系结构

    MySQL的体系结构,可以清楚地看到 SQL 语句在 MySQL 的各个功能模块中的执行过程:Server层包括连接层.查询缓存.分析器.优化器.执行器等,涵盖MySQL的大多数核心服务功能,以及所有 ...

  10. hdu4587 Two Nodes 求图中删除两个结点剩余的连通分量的数量

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 题目给了12000ms,对于tarjan这种O(|V|+|E|)复杂度的算法来说,暴力是能狗住的 ...