Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)
1 second
256 megabytes
standard input
standard output
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.
Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
5
20 30 10 50 40
4
4
200 100 100 200
2
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
题意:求最多的上升序列的个数,用map比数组快多,做法:切蛋糕一样每次切一层
代码:
#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
#include<map>
using namespace std;
int main(void)
{
int t,n,i,j,be,sum,ans;
while (cin>>n)
{
map<int,int>list;
for (i=0; i<n; i++)
{
cin>>be;
list[be]++;
}
ans=0;
while (n)//每次
{
int num=0;
for (map<int,int>::iterator it=list.begin(); it!=list.end(); it++)
{
if(it->second>0)
{
(it->second)--;
n--;
num++;
}
}
ans=ans+num-1;//两个以上才算一个上升序列
}
cout<<ans<<endl;
}
return 0;
}
Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)的更多相关文章
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Codeforces Round #345 (Div. 2) B
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces水题100道 第十三题 Codeforces Round #166 (Div. 2) A. Beautiful Year (brute force)
题目链接:http://www.codeforces.com/problemset/problem/271/A题意:给你一个四位数,求比这个数大的最小的满足四个位的数字不同的四位数.C++代码: #i ...
- Codeforces Round #277 (Div. 2)C.Palindrome Transformation 贪心
C. Palindrome Transformation Nam is playing with a string on his computer. The string consists o ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #566 (Div. 2) C. Beautiful Lyrics
链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...
随机推荐
- MySql面试题、知识汇总、牛客网SQL专题练习
点击名字直接跳转到链接: Linux运维必会的100道MySql面试题之(一) Linux运维必会的100道MySql面试题之(二) Linux运维必会的100道MySql面试题之(三) Linux运 ...
- 【Mysql】Mysql主从库搭建过程(爬完坑后整理所得)
Mysql主从数据库搭建流程 新手开始学习mysql主从库,遇到一些问题,总结后写出以下流程 下面以5.7.23版本为例介绍 第一步:去官网下载5.7.23版本的免安装压缩包形式的mysql文件,贴上 ...
- 如何使用jmeter做关联
1.适用场景 从上一个接口的返回值中获取值传递给下一个接口使用 2.添加JSON Extractor 在需求提取的参数上添加--后置处理器--JSON Extractor 从登录接口的返回值中取use ...
- thinkcmf常用标签
1.图片地址:{:cmf_get_image_url($vo.icon)} 2.模板控件 模板变量调用:$theme_vars.title <widget name="aboutUs& ...
- ise与win8兼容解决方案
win8中ise无法加载code,显示impact4.exe停止运行. 解决方法如下: 找到程序安装路径 1.进入文件夹 D:\Xilinx\14.6\ISE_DS\ISE\lib\nt64 把li ...
- Java并发编程的艺术 记录(四)
Java线程的状态: new :初始状态,但是还没调用start方法. runnable:运行状态. blocked:阻塞状态. waiting:等待状态,表示当前线程需要等待其他线程作出一些特定动作 ...
- ACM-ICPC 2015 Shenyang Preliminary Contest B. Best Solver
The so-called best problem solver can easily solve this problem, with his/her childhood sweetheart. ...
- Centos7 install Openstack Juno (RDO) (转载)
原文地址:http://www.hdume.com/centos-7-0%E5%AE%89%E8%A3%85openstack/ 1.安装系统,Centos7镜像采用CentOS-7.0-1406-x ...
- 打造一款属于自己的web服务器——从简单开始
距离开篇已经过了很久,期间完善了一下之前的版本,目前已经能够完好运行,基本上该有的功能都有了,此外将原来的测试程序改为示例项目,新项目只需按照示例项目结构实现controller和view即可,详情见 ...
- HDU 3473 Minimum Sum 划分树
题意: 给出一个长度为\(n(1 \leq n \leq 10^5)\)的序列\(a\) 有若干次查询l r:找到一个\(x\)使得\(\sum \limits_{l \leq i \leq r} \ ...