牛客网暑期ACM多校训练营(第四场) Maximum Mode(思维)

牛客网暑期ACM多校训练营(第四场)G Maximum Mode 题解 思维题 链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   Maximum Mode 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 The mode of an integer sequence is the value that... 阅读详情

链接:https://www.nowcoder.com/acm/contest/142/G
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly m of them such that: the rest integers have only one mode and the mode is maximum.

输入描述:

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m < n) -- the length of the sequence and the number of integers to delete.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) denoting the sequence.
It is guaranteed that the sum of all n does not exceed 106.

输出描述:

For each test case, output an integer denoting the only maximum mode, or -1 if Chiaki cannot achieve it.

示例1

输入

5
5 0
2 2 3 3 4
5 1
2 2 3 3 4
5 2
2 2 3 3 4
5 3
2 2 3 3 4
5 4
2 2 3 3 4

输出

-1
3
3
3
4

 

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define clr(a) memset(a,0,sizeof(a))

const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const int N = 2010;

int n,m,t;
int a[MAXN],cnt[MAXN],sum[MAXN];
map<int,int>mp;
int main(){
    scanf("%d",&t);
    while(t--){
        mp.clear();
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mp[a[i]]++;
            sum[i] = 0;
            cnt[i] = 0;//记录众数出现的个数
        }
        map<int,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            cnt[(*it).second] ++;
        }
        for(int i=n-1;i;i--){
            cnt[i] += cnt[i+1];
            sum[i] = sum[i+1]+cnt[i];
        }
        int maxx = -1;
        for(it=mp.begin();it!=mp.end();it++){
            if(sum[(*it).second]-1 <= m)
                maxx = max(maxx,(*it).first);
        }
        printf("%d\n",maxx);
    }
    return 0;
}

 

低代码Agent开发框架使用指南(二)—Coze平台核心功能概览 本篇分享系统介绍了字节跳动推出的低代码智能体开发平台Coze。Coze以免费易用、多模型支持和便捷的跨平台发布为核心优势,显著降低了智能体开发门槛。文章详细解析了平台的六大核心功能:扩展能力边界的插件系统、增强认知的知识库、结构化数据管理的数据库、可视化图像处理的图像流、实现复杂逻辑编排的工作流,以及处理复杂任务的多智能体协作机制,全面展现了Coze平台的强大能力。 阅读详情

相关推荐

什么是 MDB-RS232,为什么需要 MDB-RS232适配器 ?

在您需要设计一个售货机,首先需要选择适合您机器的主板,比如安卓主板、树莓派、工控机或者PLC等,这些主板都是没有MDB接口的,而支付设备,比如你选择的纸币器,硬币器,都是MDB接口。那您就需要这个 MDB 适配器,来把MDB接口的支付设备连接到这些串口的主板上,进行通信和控制。MDB-RS232旨在将MDB 协议转换为 RS232 协议,并执行必要的电压转换以及数据路由工作。,能够让主板轻松执行其他任务,不需要考虑协议的具体软硬件的兼容和稳定性问题。专业的设计指导和协助协议分析,丰富的开发文档。

waferstar的博客 1384

牛客网暑期ACM多校训练营(第四场)G Maximum Mode 【枚举】

链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 The mode of an integer sequence is the value that appears most ...

Head_Hard的博客 368

Unity Tilemap瓦片动态缩放:保持网格尺寸不变的三种实现方案

本文详细探讨了在Unity中实现Tilemap瓦片动态缩放同时保持网格尺寸不变的三种核心方案。针对编辑器静态调整、整体风格化处理及运行时动态控制等不同场景,分别解析了直接修改瓦片属性、调整Tilemap Renderer材质参数以及使用SetTransformMatrix与Matrix4x4矩阵变换的实践方法、优缺点及选型指南,为2D游戏开发提供灵活高效的视觉与交互解决方案。

grass的博客 631

牛客网暑期ACM多校训练营(第四场)G Maximum Mode(思维)

链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 The mode of an integer sequence is the value that appears most ...

LSD20164388的博客 408

thinkcmf 代码执行 (CVE-2019-7580) 漏洞复现

所有文章,仅供安全研究与学习之用,后果自负! thinkcmf 代码执行 CVE-2019-7580thinkcmf 代码执行 (CVE-2019-7580)0x01 漏洞描述0x02 影响范围0x03 漏洞复现3.1 登录后台3.2 漏洞利用3.2.1webshell3.2 phpinfo3.3 获取系统命令0x04 漏洞修复 thinkcmf 代码执行 (CVE-2019-7580) 复现小心会搞崩环境。 0x01 漏洞描述 ThinkCMF是一款支持Swoole的开源内容管理框架(CMF),基于Thi

YouthBelief的博客 4269

MRI图像切片(nii格式转2D)

代码参考:将一个MRI(nii格式)数据进行切片 想要批量抽取MRI数据的几个切片,借鉴了上述代码的Python版本,原始代码抽取了全部切片。本次实验主要是抽取sMRI的横断面(axial)方向的其中30张切片,数量根据自己需求可自行设置。 import scipy, numpy, shutil, os, nibabel import sys, getopt import imageio def niito2D(filepath): inputfiles = os.listdir(filep

chs_502的博客 7553

牛客网暑期ACM多校训练营(第四场)G.Maximum Mode (思维)

题目链接 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She wou...

Fushicho_XF的博客 518

HI3516CV610海思SOC:超高清智慧视觉开发全攻略

本文全面解析海思HI3516CV610 SOC在超高清智慧视觉开发中的应用。该芯片集成双核A7处理器、1Tops NPU、AI ISP及4K视频编码器,专为智能摄像头设计。文章详细介绍了开发环境搭建、核心硬件架构、媒体处理平台(MPP)实战、AI算法集成与系统调优等全流程攻略,帮助开发者高效构建稳定可靠的视觉AI产品。

weixin_29269441的博客 1265

牛客网多校训练赛Maximum Mode(思维)

题目链接https://www.nowcoder.com/acm/contest/142/G 题意求n个数中删去m个数能得到的最大众数,若无则输出-1 思路:枚举最大众数的值,看是否能得到该结果。 #include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt;...

reallsp的博客 333

Windows下用MSYS2一键搞定Verilator安装(附国内镜像加速)

本文详细介绍了在Windows系统下,如何利用MSYS2工具和国内镜像源,快速、高效地完成Verilator的安装与配置。通过替换清华镜像源加速下载,并配合Pacman包管理器,实现近乎一键式的安装流程,有效解决了传统方法步骤繁琐、网络依赖下载慢的问题,为数字电路仿真提供了便捷的Windows环境解决方案。

weixin_29208327的博客 605

GSEA富集分析实战:从数据准备到结果解读的完整R代码指南

本文提供了一份完整的GSEA富集分析实战指南,涵盖从R环境准备、数据质量控制到基因ID转换、参数优化和结果解读的全流程。通过详细的R代码示例和实用技巧,帮助研究人员高效完成基因集富集分析,特别针对生物信息学中常见的GSEA分析痛点提供了专业解决方案。

weixin_29246195的博客 543

牛客多校训练营Maximum Mode

链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   题目描述 The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly ...

Pandapan1997的博客 354

从零开始学习PX4源码20(遥控器模式切换如何执行)

本节主要学习PX4的手动遥控器切换模式,具体是如何实现的,具体改变了哪些变量,和模式管理有什么联系。

陌城烟雨 321

牛客网暑期ACM多校训练营(第四场)G Maximum Mode(模拟+思维)

链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   Maximum Mode 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 The mode of an integer sequence is the value that...

qq_41668093的博客 306

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

牛客网暑期ACM多校训练营(第四场)G Maximum Mode(思维)

链接: https://www.nowcoder.com/login?callBack=%2Facm%2Fcontest%2F142%2FG 题意: 给定n个数, 要求删去恰好m个数后的最大总数是多少。 分析: 要使一个数是众数, 只要比他大的数的数量都比自己小就行。 预处理出全部出现次数的最大数(例如, 出现3次最大的是1,出现2次最大的是2等等)。 然后从最大的次数开始...

dixianqi2609的博客 132

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

牛客网暑期ACM多校训练营(第四场) G Maximum Mode 思维

链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly m o...

weixin_33943347的博客 101

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

牛客网暑期ACM多校训练营(第四场) G

链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   题目描述 The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly ...

liluoyu_1016的博客 242

牛客网暑期ACM多校训练营(第四场)Maximum Mode

链接:https://www.nowcoder.com/acm/contest/142/G 来源:牛客网   时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 The mode of an integer sequence is the value that appears most ...

gtuif的博客 267

牛客网暑期ACM多校训练营(第四场)G(Maximum Mode)

题目描述  The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly m of them such that: the rest integers have only one mod...

snayf的博客 204

牛客网暑期ACM多校训练营(第四场)- (D,F,G)

D Another Distinct Values 题意:用数值1、0、-1来组成一个n*n的矩阵,使得这个矩阵的每一行之和、每一列之和互不相同。 解析:如果n是奇数则构造不出来(还不会证明。。。),如果是偶数则按如下方法构造: 构造方法一:  n=4 1  1  0  0 1  1  0 -1 1  1 -1 -1 1  0 -1 -1 n=6 1  1  1  0  0 ...

Orz 309

牛客第四次多校Maximum Mode

链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 题目描述 The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete ...

weixin_30578677的博客 186

A. Ternary String 牛客网暑期ACM多校训练营(第四场)

 A. Ternary String  牛客网暑期ACM多校训练营(第四场) 题目链接 A ternary string is a sequence of digits, where each digit is either 0, 1, or 2. Chiaki has a ternary string s which can self-reproduce. Every second, a d...

brandong 528

牛客练习赛19-F-托米搭积木

链接:https://www.nowcoder.com/acm/contest/111/F来源:牛客网托米搭积木时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld题目描述 小托米真的很可爱呀(&gt;_&lt;) 这天,可爱的小托米得到了n堆积木,且第i堆积木初始时有ai块积木. 小托米很快就喜欢上...

恒持此志成永志 580

2018暑假牛客多校(第四场)

G-Maximum Mode G-Maximum Mode 题意:删除 MMM 个数,使得众数唯一,并输出最大的众数 哎~签到题都签不完(;´д`)ゞ 这是lzj童鞋的思路: 把可能成为最大众数的数从大到小排序,然后检查要是符合条件,那么众数就是他了~ 怎么检查呢? 先把所有数的次数放在一个 bbb 数组里面,然后升序排序 举个栗子: 9,9,9,9,8,8,8,8...

帅气廖鹏飞 403

牛客网暑期ACM多校训练营(第四场)J Hash Function(拓扑排序思想)

链接:https://www.nowcoder.com/acm/contest/142/J 来源:牛客网   时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 Chiaki has just learned hash in today's lesson. A hash function...

LSD20164388的博客 462
上一篇: HDU-6330 Problem L. Visual Cube(模拟)
下一篇: HDU-6299 Balanced Sequence(贪心)
辞树 LingTree
博客等级 码龄10年 478粉丝 472原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值