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的整数倍的点上分布着灯笼,而在 ...
随机推荐
- nor flash之4字节地址模式
背景 容量低于 16M bytes 的 nor,一般使用 3 字节地址模式,即命令格式是 cmd + addr[2] + addr[1] + addr[0] + ... 使用超过 16M bytes ...
- vijos 1449 字符串还原
背景 小K是一位蔚蓝教主的崇拜者(Orz教主er),有一天,他收到了一封匿名信,信告诉了小K由于他表现出色,得到了一次当面Orz教主的机会,但是要当面Orz教主可不那么容易,不是每个人都有资格Orz教 ...
- sentinel 规则持久化到nacos
问题描述 Sentinel Dashboard中添加的规则是存储在内存中的,只要项目一重启规则就丢失了 此处将规则持久化到nacos中,在nacos中添加规则,然后同步到dashboard中: 后面研 ...
- npm install、npm install --save与npm install --save-dev、npm install -g区别
npm install X: 会把X包安装到node_modules目录中 不会修改package.json 之后运行npm install命令时,不会自动安装X npm install X –sav ...
- svn更新时同步web服务器
1.重中之重:第一次更新需要先把数据库先检索出来,执行脚本./post.commit #!/bin/sh export LANG=en_US.UTF-8 SVN=/usr/local/subversi ...
- vue-cli实现最简单的全选、全不选、反选功能。不容错过呦!!!!!话不多说直接上代码。。。。
<template> <div class="hello"> <input type="button" name="al ...
- WINDOWS上JDK安装与环境变量设置
一.JDK安装 jdk版本:jdk1.8.0_144 下载链接:https://pan.baidu.com/s/1eS2bFhg 密码:e3q1 下载JDK后点击安装,可以根据需要修改JDK的安装目录 ...
- (转)协议森林02 小喇叭开始广播 (以太网与WiFi协议)
协议森林02 小喇叭开始广播 (以太网与WiFi协议) 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们在邮差与邮局中说到,以 ...
- computed 里面 不能写箭头函数 都要写 function () {} 否则页面会都不显示
computed 里面 不能写箭头函数 都要写 function () {} 否则页面会都不显示
- rpc框架dubbo学习入门及环境搭建(spring boot+Kotlin)
学习之前,确保有以下知识基础: Java网络编程 Socket传输数据 IO流 rpc简介及实现 rpc是remote procedure call的简写,意思为远程过程调用. rpc应用较多的情景是 ...