首页 > 其他分享 >1001.选班长

1001.选班长

时间:2024-07-28 15:24:11浏览次数:9  
标签:10 int 999 选票 班长 include 1001 候选人

班级正在选举班长,有n(n≤999)名候选人,每名候选人编号分别从 1 到 �n,现在收集到了m(m≤2000000)张选票,每张选票都写了一个候选人编号。现在想把这些堆积如山的选票按照投票数字从小到大排序并写出选举票数最多的序号。

输入格式

第一行为�n �m

第二行为�m张票 中间用空格隔开

输出格式

第一行为排好序的投票结果(中间用空格隔开)

第二行为选中的序号

样例

输入

5 10
2 5 2 2 5 2 2 2 1 2

输出

1 2 2 2 2 2 2 2 5 5
2

数据范围

1≤n≤999

1≤m≤2000000

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

using namespace std;
const int N = 2e5 + 10;
int n, m, k = 0;
int a[N];
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> k;
        a[k]++;
    }
    int max = a[0];
    int c = 0;
    for (int i = 1; i <= n; i++)
        if (max < a[i])
        {
            max = a[i];
            c = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < a[i]; j++)
            cout << i << " ";
    cout << endl;
    cout << c;
    return 0;
}

标签:10,int,999,选票,班长,include,1001,候选人
From: https://blog.csdn.net/wang4518/article/details/140750706

相关文章

  • 1001 A+B Format
    Calculatea+bandoutputthesuminstandardformat--thatis,thedigitsmustbeseparatedintogroupsofthreebycommas(unlesstherearelessthanfourdigits).InputSpecification:Eachinputfilecontainsonetestcase.Eachcasecontainsapairof......
  • 2024“钉耙编程”中国大学生算法设计超级联赛(1)第一场1001
    循环位移题解2024“钉耙编程”中国大学生算法设计超级联赛(1)题目:ProblemDescription定义字符串S=S0+⋯+Sn−1循环位移k次为S(k)=Skmodn+⋯+Sn−1+S0+⋯+S(k−1)modn。定义[A]=\setA(k),k∈N.给出T组串A,B,询问B有多少个子串在[A]中。Input第一行一个......
  • 1001:Hello,World! 题解
    题目链接题目描述编写一个能够输出“\(\mathtt{Hello,World!}\)”的程序,这个程序常常作为一个初学者接触一门新的编程语言所写的第一个程序,也经常用来测试开发、编译环境是否能够正常工作。提示:“\(\mathtt{Hello,World!}\)”中间没空格。解题思路梦开始的地方\(Ver3.0\)没......
  • HDU1000,HDU1001,HDU1002,HDU1003,HDU1004
    目录HDU1000——A+BProblem题目描述运行代码代码思路HDU1001——SumProblem题目描述运行代码代码思路HDU1002——A+BProblemII(高精度加法)题目描述运行代码代码思路高精度加法模板HDU1003——MaxSum题目描述运行代码代码思路HDU1004——LettheBall......
  • 「清新题精讲」Gym100198H - Royal Federation
    H-RoyalFederation\(\mathsf{\color{Thistle}Statement}\)给定一棵\(n\)个点的树,将其划分为\(m\)个集合(\(m\)可以为任意正整数),对于每个集合,顷定其特殊点,使得该点可以到达属于该集合内的所有点只经过集合内的点(注意特殊点可以不在集合内),其中集合大小要求在\(B\sim3B\)......
  • Django Error: [WinError 10013] An attempt was made to access a socket in a way f
      D:\06softw-dev-202306\manage.pyrunserverWatchingforfilechangeswithStatReloaderPerformingsystemchecks...Systemcheckidentifiednoissues(0silenced).May03,2024-10:02:12Djangoversion3.2.18,usingsettings'MPDB.settings......
  • nginx报错:bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a soc
    问题:1.nginx启动失败2.在logs/error.log文件下,出现报错信息:bind()to0.0.0.0:80failed(10013:Anattemptwasmadetoaccessasocketinawayforbiddenbyitsaccesspermissions) 目录:1、cmd输入命令netstat-aon|findstr"80"2.、查看80端口7532对应的任务3、......
  • MHY1001. [崩三]椰子树题解
    #include<bits/stdc++.h>usingnamespacestd;constintN=1010,M=20010;intq[M];//s的最大值为20000,v的最小值为1,所以队列里面最多是会有200010个元素的intn,m;intf[M],g[M];intmain(){cin>>n>>m;for(inti=1;i<=n;++i){......
  • 【转载】解决 安装或卸载软件时报错Error 1001 的问题
    卸载或安装程序时出错1001:错误1001可能发生在试图更新、修复或卸载windowsos中的特定程序时。此问题通常是由于程序的先前安装损坏而引起的。错误“1001”通常会遇到,因为程序的先前安装被破坏或者由于Windows安装不处于正常状态(例如,注册表已经被恶意软件修改)。在这种情况......
  • [Blazor] 学习随笔——RZ10012警告的处理
    程序能运行,就是告诉你RZ10012,然后各种提示没有了。清理解决方案、电脑重启了都没有用,后来搜索到github,解决了,记一下:关闭vs删除文件夹.vs,bin,object打开vs,重新生成解决方案也是醉了。文字少的博文不允许投稿到该网站分类?知道什么叫短小精悍吗?知道什么叫短小精悍吗?知道什......