Polycarp's Pockets(思维)
Polycarp has nn coins, the value of the ii-th coin is aiai. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array a=[1,2,4,3,3,2]a=[1,2,4,3,3,2], he can distribute the coins into two pockets as follows: [1,2,3],[2,3,4][1,2,3],[2,3,4].
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input
The first line of the input contains one integer nn (1≤n≤1001≤n≤100) — the number of coins.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100) — values of coins.
Output
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Examples
Input
6
1 2 4 3 3 2
Output
2
Input
1
100
Output
1
题解:找出现重复次数最多的元素的数量即可
AC代码1:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() {
int n;
cin>>n;
int a[105];
for(int t=0; t<n; t++) {
scanf("%d",&a[t]);
}
sort(a,a+n);
int maxn=1;
int sum=1;
for(int t=0; t<n-1; t++) {
if(a[t]==a[t+1]) {
sum++;
} else if(a[t]!=a[t+1]) {
sum=1;
}
if(maxn<sum) {
maxn=sum;
}
}
cout<<maxn<<endl;
return 0;
}
AC代码2:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int sum[101]={0};
int n;
cin>>n;
int k;
for(int t=0;t<n;t++)
{
scanf("%d",&k);
sum[k]++;
}
int maxn=1;
for(int t=1;t<=100;t++)
{
if(sum[t]>maxn)
{
maxn=sum[t];
}
}
cout<<maxn<<endl;
return 0;
}
Polycarp's Pockets(思维)的更多相关文章
- 7.24-Codeforces Round #494 (Div. 3)
链接:http://codeforces.com/contest/1003 A. Polycarp's Pockets 题型:模拟 题意:把初始集合拆分,要求相同的数不在同一个集合中,求出需要的集合个 ...
- Codeforces Round #494 (Div 3) (A~E)
目录 Codeforces 1003 A.Polycarp's Pockets B.Binary String Constructing C.Intense Heat D.Coins and Quer ...
- CF1005D Polycarp and Div 3 思维
Polycarp and Div 3 time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- CodeForces 1005D Polycarp and Div 3(思维、贪心、dp)
http://codeforces.com/problemset/problem/1005/D 题意: 给一个仅包含数字的字符串,将字符串分割成多个片段(无前导0),求这些片段里最多有多少是3的倍数 ...
- cf-789A (思维)
A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3
今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
随机推荐
- LOJ2722 「NOI2018」情报中心
「NOI2018」情报中心 题目描述 C 国和D 国近年来战火纷飞. 最近,C 国成功地渗透进入了D 国的一个城市.这个城市可以抽象成一张有$n$ 个节点,节点之间由$n - 1$ 条双向的边连接的无 ...
- ACM学习历程—HDU5423 Rikka with Tree(搜索)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- BZOJ1707:[Usaco2007 Nov]tanning分配防晒霜
我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...
- JAVA 1.5 并发之 BlockingQueue
1.BlockingQueue 顾名思义就是阻塞队列 最经典的使用场合就是 生产者 - 消费者 模型啦,其优点是队列控制已经处理好,用户只需要存(满了会阻塞),取(空了会阻塞) 可以更多的关心核心逻辑 ...
- MyEclipse 手动安装Velocity 编辑器
最近项目有使用Velocity 模板引擎,从而会用到*.VM页面!Myeclipse打开VM页面字体一片漆黑,哪有JSP那样看起来舒服(个人感觉)!为了解决这一问题就要安装Velocity编辑器,安装 ...
- 一 Optional
从Java8 引入的一个很有趣的特性是Optional类.Optional类主要解决的问题是臭名昭著的空指针异常(NullPointerException). 一: 创建Optional对象: ...
- "LPWSTR" 类型的实参与"const.char *"类型形参不兼容
CString csPlus; CString csSummand; m_PlusNumber.GetWindowTextW(csPlus); m_Summand.GetWindowTextW(csS ...
- 超牛 猴子补丁,修改python内置的print
猴子补丁一般是用于修改三方包或官方包,也可以用来修改自己或者他人的代码. 但也可以用来修改python 语言内置的关键字. 本篇博客修改python最常用的内置print,使你使用print时候,自动 ...
- 设置win7资源管理器启动时的默认位置-windows-操作系统-网页教学网
设置win7资源管理器启动时的默认位置-windows-操作系统-网页教学网 如何设置win7资源管理器启动时的默认位置?我不太习惯 Win 7 的资源管理器默认总是打开库,我还是喜欢资源管理器打开树 ...
- struts 文件上传示例
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...