codeforces 651B Beautiful Paintings

对halcon形状匹配算法的一点分析 基于Intel VTune Profiler对halcon形状匹配算法的一点分析 阅读详情

B. Beautiful Paintings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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.

Output

Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

Examples
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2
Note

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.


算是一个贪心吧,看数列的哪一个排列能够使相邻的两个元素前一个比后一个大的情况最多

先从大到小排序,然后用一个vis标记这个数有没有用过,找到第一个没有用过的最小的,然后往后扫尽可能多的连续的递增的数,反复这样做,直到所有的数都遍历一遍

需要注意的是有可能有重复的数字


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

int a[1005];
bool vis[1005];

int main()
{
	int n;
	memset(vis, false, sizeof(vis));
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	//升序排列
	sort(a, a + n);
	int cou = 0, ans = 0;

	while (cou != n) {
		int i;
		//找到第一个没有用过的最小的数a[i]
		for (i = 0; i < n; i++) {
			if (!vis[i]) {
				vis[i] = true;
				cou++;
				break;
			}
		}
		//从a[i + 1]开始找尽可能长的递增的数列
		for (int j = i + 1; j < n; j++) {
			if (!vis[j] && a[j] > a[i]) {
				vis[j] = true;
				cou++;
				ans++;
				i = j; // 记得改变i
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}








STM32F407中文手册 STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。 立即下载

相关推荐

饥荒联机版Mod开发——modmain环境与API深度解析

本文深入解析饥荒联机版Mod开发中的modmain.lua环境与核心API,详细讲解环境表构建原理、API注册与调用时机,并提供高级开发技巧与最佳实践。通过源码分析和实际案例,帮助开发者掌握Mod开发核心技术,解决常见问题,提升开发效率与代码质量。

weixin_30312563的博客 432

CodeForces 651B Beautiful Paintings

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There arenpictures delivered for the new exhibition....

weixin_30314813的博客 146

第一篇:常见CAN错误帧及其排查方向

在本文中主要阐述各类错误帧的形成原因以及在使用同星硬件设备出现错误帧时,应当 如何进行排查并消除错误帧。在 CAN 总线通信中,通常遇见的错误帧主要为以下五种,其 分别是:bit error、ACK error、stuff error、CRC error 以及 form error。

u013089100的博客 1731

Codeforces 651B Beautiful Paintings(贪心策略—两个优先队列实现)

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for th

Chunzhen的博客 1096

vivo X200 Ultra前瞻系列(1):重塑影像旗舰标准

在色彩风格化、视频专业度上实现了安卓阵营的突破性进步。其2亿像素长焦、双LYT-818传感器及5轴防抖技术,对追求个性化创作的用户具有强吸引力。若真机表现能兑现硬件承诺,X200 Ultra有望重新定义手机影像的“专业”标准。然而,其厚重设计、价格门槛及生态适配问题,仍需市场检验。vivo X200 Ultra作为2025年上半年影像旗舰,以“全焦段夜视仪+电影级视频”为核心卖点,主打。,对标小米15 Ultra、OPPO Find X8 Ultra等竞品。,顶配版(24GB+2TB)逼近万元。

专注:太空算力、AI infra、异构调度、大模型成本工程 963

YOLOv8改进策略【Neck】| CVPR 2024 MFM(Modulation Fusion Module,调制融合模块):动态特征加权融合,突出关键特征抑制冗余

本文主要利用DCMPNet中的 MFM 模块优化 YOLOv8 的目标检测网络模型。模块通过动态调制特征融合过程,实现了对多尺度、跨层级特征的智能聚合。将其应用于的改进过程中,针对目标检测中边界特征与语义信息的互补性需求,缓解网络中浅层细节与深层语义融合不足的问题。Depth Information Assisted Collaborative Mutual Promotion Network for Single Image Dehazing在图像去雾网络中,不同层级和类型的特征包含着互补的信息(如浅层的

Limiiiing的博客 351

Beautiful Paintings

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for th

qq_40510246的博客 559

华为OD新系统机试真题-8位LED控制器(C/C++/Py/Java/Js/Go)

华为OD新系统机试真题【8位LED控制器】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD新系统4月19号机试真题【8位LED控制器】

qq_45776114的博客 596

Codeforces 651B Beautiful Paintings【思维】

题目链接:Codeforces 651B Beautiful Paintings

世界很大 723

KCP(快速可靠UDP)——用带宽换延迟的极致艺术

想象你是一个外卖平台的调度员。这就是KCP的本质——

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 202

华为OD新系统机试真题-文章特征提取

华为OD机试新系统真题 【文章特征提取】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD新系统机试真题【文章特征提取】

qq_45776114的博客 729

【Codeforces】CF651B-Beautiful Paintings

原题链接:https://codeforces.com/contest/651/problem/B 题目大意 给定n个数,设法对其进行重组,使得重组后的数组中ai+1&gt;aia_{i+1}&gt;a_iai+1​>ai​的情况最多(对所有1⩽i⩽n−11\leqslant i \leqslant n-11⩽i⩽n−1)。 解法 观察到数据范围很小,可以hash进桶后暴力枚...

xy160322的博客 247

如何选择深度强化学习算法:MuZero/SAC/PPO/TD3/DDPG/DQN/等算法

如何选择深度强化学习算法:MuZero/SAC/PPO/TD3/DDPG/DQN/等算法

丨汀、的博客 5221

【CodeForces】651B - Beautiful Paintings

Description 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 o

WOLF的博客 499

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

CodeForces - 651B Beautiful Paintings

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 allowe...

Wolfgang 387

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【CodeForces】[651B]Beautiful Paintings

刚开始以为是简单的排序 后来发现是重新排列后 只要有 a[i+1]>a[i]变使cnt++ 所以最优排列方法可以是 类似于12312312323333这种

BoilTask Talk Show 438

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces 651B Beautiful Paintings【贪心】

题意:给定序列,重新排序,使严格上升的子序列最多。求这些子序列总长度。分析:贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素。代码:#include<iostream> #include<algorithm> using namespace std; const int maxn = 1005; int a[maxn]; int m[maxn]; int main (voi

Tuesday 400

【CodeForces】651B - Beautiful Paintings(暴力)

题目链接:点击打开题目 B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictur

wyg1997 1018

【codeforces 651B - Beautiful Paintings 】 greedy(贪心)

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputThere are n pictures delivered for the new exhibition. The i-t

ATOD 1228

CodeForces 651B Beautiful Paintings

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for th

neversayno_yl的博客 336

思维 CodeForces - 651B Beautiful Paintings

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for the new exhi

PiKa__Qiu的博客 409

codeforces--651B Beautiful Paintings

题解桶排的思想,累加每个严格递增的序列的长度减一的值。n = int(input()) a = [int(x) for x in input().split()] vis = [0] * 1005 for i in range(n): vis[a[i]] += 1 ans = 0 while n: num = 0 for i in range(1, 1001):

许少y 474

codeforces 651B Beautiful Paintings【优先队列】

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for th

wyjwyl的专栏 453
上一篇: codeforces 651A Joysticks
下一篇: hdu5650 so easy 组合数
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值