codeforces Towers 题解
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer N (1 ≤ N ≤ 1000)
— the number of bars at Vasya’s disposal. The second line contains N space-separated integers li —
the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
3
1 2 3
1 3
4
6 5 6 7
2 3
题意就是计算一个数组中的最大反复数和去重后的数据量。
所以本题就是数组去重知识的运用,和添加一个记录,记录最大反复数。
void Towers()
{
unsigned n;
cin>>n;
int *A = new int[n]; for (unsigned i = 0; i < n; i++)
{
cin>>A[i];
}
sort(A, A+n);
int j = 1, h = 1, max_h = 1;
for (unsigned i = 1; i < n; i++)
{
if (A[i] != A[i-1])
{
A[j++] = A[i];
max_h = max(max_h, h);
h = 1;
}
else h++;
}
max_h = max(max_h, h);
cout<<max_h<<' '<<j; delete [] A;
}
codeforces Towers 题解的更多相关文章
- codeforces#536题解
CodeForces#536 A. Lunar New Year and Cross Counting Description: Lunar New Year is approaching, and ...
- codeforces 1093 题解
12.18 update:补充了 $ F $ 题的题解 A 题: 题目保证一定有解,就可以考虑用 $ 2 $ 和 $ 3 $ 来凑出这个数 $ n $ 如果 $ n $ 是偶数,我们用 $ n / 2 ...
- Codeforces Numbers 题解
这题只需要会10转P进制就行了. PS:答案需要约分,可以直接用c++自带函数__gcd(x,y). 洛谷网址 Codeforces网址 Code(C++): #include<bits/std ...
- Codeforces 691E题解 DP+矩阵快速幂
题面 传送门:http://codeforces.com/problemset/problem/691/E E. Xor-sequences time limit per test3 seconds ...
- Codeforces 833B 题解(DP+线段树)
题面 传送门:http://codeforces.com/problemset/problem/833/B B. The Bakery time limit per test2.5 seconds m ...
- Codeforces 840C 题解(DP+组合数学)
题面 传送门:http://codeforces.com/problemset/problem/840/C C. On the Bench time limit per test2 seconds m ...
- Codeforces 515C 题解(贪心+数论)(思维题)
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
- CodeForces CF875C题解
题解 非常有意思的\(2-SAT\)的题. 听学长讲完之后感觉确实容易想到\(2-SAT\),顺理成章. 显然,对于两个串,对咱们来说有意义的显然是两个串中第一个不同的数字.那么,我们假设两个串分别是 ...
随机推荐
- systemd实践: 依据情况自动重启服务
systemd服务异常自动重启很好用,但有的时候希望某些服务只在特定情况下进行重启,其他时候不要自动重启(比如OOM,需要人工介入). 本文抛砖引玉,旨在能够让读者对systemd的重启机制有一定了解 ...
- classname在JavaScript中的应用
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...
- jquery mobile动态加载数据后无法渲染
引自:http://blog.sina.com.cn/s/blog_025270e901016lst.html jquery mobile在动态添加html之后无法渲染控件,无法转换控件的办法! jq ...
- MongoDB 博客截图之一
来源:十天掌握MongoDB之三:学会Find - 学吧网 - 专注于PHP资源分享
- smarty 3 + codeigniter 2 + hmvc
参考资料 https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src/fecd39ccdf56?at=defau ...
- JS操作DOM的一些常用方法
getElementById():获取有指定惟一ID属性值文档中的元素 getElementsByName(name):返回的是数组 getElementsByTagName():返回具有指定标签名的 ...
- Lazy Initialization with Swift
Lazy initialization (also sometimes called lazy instantiation, or lazy loading) is a technique for d ...
- DB2常用运维命令
DB2是IBM公司推出关系型数据库管理系统.主要应用于银行.医院等大型机构.现今DB2主要包含以下三个系列:DB2 for Linux, UNIX and Windows(LUW) . DB2在Lin ...
- CentOS 7添加开机启动服务/脚本
一.添加开机自启服务 在CentOS 7中添加开机自启服务非常方便,只需要两条命令(以 jenkins 为例):systemctl enable jenkins.service #设置jenkins服 ...
- 洛谷P1466 集合 Subset Sums_01背包水题
不多解释,适当刷刷水… Code: #include<cstdio> #include<algorithm> using namespace std; const int ma ...