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\),顺理成章. 显然,对于两个串,对咱们来说有意义的显然是两个串中第一个不同的数字.那么,我们假设两个串分别是 ...
随机推荐
- 【POJ 3696】 The Luckiest number
[题目链接] http://poj.org/problem?id=3696 [算法] 设需要x个8 那么,这个数可以表示为 : 8(10^x - 1) / 9, 由题, L | 8(10^x - 1) ...
- 多线程之HttpClient
在程序用调用 Http 接口.请求 http 资源.编写 http 爬虫等的时候都需要在程序集中进行 Http 请求. 很多人习惯的 WebClient.HttpWebRequest 在 TPL 下很 ...
- 如何使用fetch
Fetch API 提供了一个 JavaScript接口,用于访问和操纵HTTP管道的部分,例如请求和响应.它还提供了一个全局fetch()方法,该方法提供了一种简单,合乎逻辑的方式来跨网络异步获取 ...
- HTML实现图片360度循环旋转
<style> .header{ -webkit-animation:rotateImg 5s linear infinite;<!--修改旋转周期--> border: 1p ...
- Docker的官网在线--中文教程
1.官网界面:https://www.docker.com/tryit/ In this 10-minute tutorial, see how Docker works first-hand: Yo ...
- C# DataTable 转 json
public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //窗体 ...
- pymmseg 安装方法以及乱码解决
pymmseg-cpp is a Python port of the rmmseg-cpp project. rmmseg-cpp is a MMSEG Chinese word segmentin ...
- ZBrush的双十一来了,然鹅...
不管是“光棍节”还是“剁手节” 似乎和我都没有什么关系 事实证明,我错了 今早竟然有不识趣的人发红包祝我单身快乐 纳尼,这是唱的哪一出? 我能直接怼回去,说不领么? 但好像又不是我的风格 哎,一个红包 ...
- input输入值限制
限制输入框只能输入数字并且保留两位小数 <input type= "text" onkeyup="var p2 = parseFloat(value).toFixe ...
- Vue中的v-model与my97日期选择插件冲突
Vue中的v-model指令只是一个语法糖,其具体实现是:监听input框的input事件,然后将用户输入的值赋值给input框的value属性 <input type="text&q ...