当前位置:网站首页>[noip2006 popularity group] clear random number
[noip2006 popularity group] clear random number
2022-07-18 23:12:00 【ceshyong】
notes : The title of this topic is random.
Title Description
I want to invite some students to do a questionnaire survey at school , For the objectivity of the experiment , He first generated... By computer N individual 1 To 1000 Random integer between (N≤100), For the repeated numbers , Keep only one , Take out the rest of the same number , Different numbers correspond to different student numbers . And then sort the numbers from small to large , According to the order of arrangement to find students to do research . Please help Mingming finish “ duplicate removal ” And “ Sort ” The job of .
Input
Input yes 2 That's ok , The first 1 Behavior 1 A positive integer N, Represents the number of generated random numbers .
The first 2 Yes N Positive integers separated by spaces , For the resulting random number .
Output
The output is 2 That's ok , The first 1 Behavior 1 A positive integer M, The number of different random numbers . The first 2 Behavior M Positive integers separated by spaces , Different random numbers in order from small to large .
Sample group
Input
10
20 40 32 67 40 20 89 300 400 15
Output
8
15 20 32 40 67 89 300 400Topic ideas
There are two approaches to this topic .
The first approach relies mainly on the use of hash tables . The program using hash table is relatively straightforward ( Simple algorithm ), But you need to redefine the array to get from the element , And variables K To show how many elements there are . The main program written with hash table is as follows :
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m;
a[m]++;
}
for(int i=1;i<=1000;i++)
if(a[i]>0) b[++k]=i;
cout<<k<<endl;
for(int i=1;i<=k;i++) cout<<b[i]<<' ';
return 0;
}The second way of writing needs the help of STL Inside set. We can rely on set in The value of each element is unique This is used to insert when inputting , Then you can directly output the number of elements (.size()), Then use iterators (iterator) That's it . use set The main program written is as follows :
int main()
{// There is really only input and output
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m;
a.insert(m);
}
cout<<a.size()<<endl;
for(it=a.begin();it!=a.end();it++) cout<<*it<<' ';
return 0;
}Topic scale
The scale of this topic is as follows :
Hash table scale :
#include<bits/stdc++.h>
#define N 1005
using namespace std;
int n,a[N],m,k,b[N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m;
a[m]++;
}
for(int i=1;i<=1000;i++)
if(a[i]>0) b[++k]=i;
cout<<k<<endl;
for(int i=1;i<=k;i++) cout<<b[i]<<' ';
return 0;
}STL Standard range :
#include<bits/stdc++.h>
using namespace std;
set<int>::iterator it;
set<int>a;int n,m;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m;
a.insert(m);
}
cout<<a.size()<<endl;
for(it=a.begin();it!=a.end();it++) cout<<*it<<' ';
return 0;
}There are so many questions .
边栏推荐
- Developers must see | devweekly issue 1: what is time complexity?
- SQL Server 各种锁 NOLOCK、UPDLOCK、HOLDLOCK、READPAST
- 2022 soft test network administrator preparation guide
- Leetcode daily question (947. most stones removed with same row or column)
- Can't go on, mend the foundation -- C thread develops output string program
- Shallow copy and deep copy
- [paddleseg source code reading] about the trivial matter that the paddleseg model returns a list
- [fluent -- actual combat] dart language quick start
- 11(2).结构体的存储方式,结构体变量和结构体变量指针作为函数参数传递的问题,指针的优点
- 【开发教程3】疯壳·ARM功能手机-整板资源介绍
猜你喜欢

微信小程序--》小程序简介与工具安装配置

Deepmind's latest 114 page report "emerging barter trade behavior in Multi-Agent Reinforcement Learning"

vi编辑器设置自定义快捷键自动生成c语言的main函数

【C语言】strlen函数的讲解和模拟实现

10分钟自定义搭建行人分析系统,检测跟踪、行为识别、人体属性All-in-One

基于多数据源零代码同时生成多个数据库CRUD增删改查RESTful API接口——MySql,PostgreSql,Oracle,Microsoft SQL Server多数据源

leetcode--242. 有效的字母异位词

Private domain operation is very popular. Is private domain operation suitable for all enterprises?

Comparative investigation of three commonly used time series databases - incluxdb, Prometheus, iotdb

sklearn线性回归完成多次项函数和正弦函数拟合
随机推荐
Cache design
10分钟自定义搭建行人分析系统,检测跟踪、行为识别、人体属性All-in-One
Is there any prospect for individuals to do overseas social media? Any good suggestions?
C语言自定义类型:结构体,枚举,联合
Picasso, an efficient search generalization sparse training solution
[Ji Zhong] July 13, 2022 3058 Torchbearer
Z-Wave CTT usage and test demonstration
[NOIP2006普及组]明明的随机数
The difference between NPM and NPX
Professor Liu Xiaole: my indissoluble relationship with bioinformatics
Developers must see | devweekly issue 1: what is time complexity?
leetcode--242. Valid alphabetic ectopic words
20220714 adapt openharmony-v3.1-beta to aio-3568j (compile builderoot)
mysql忘记密码重置
【开发教程1】开源蓝牙心率防水运动手环-套件检测教程
How to deal with time series event data? [doctoral thesis of Munich University of technology] neural time series point process (ntpp): continuous time event data modeling
ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing‘
常用放大器基础知识(上)
3D point cloud course (II) -- nearest neighbor problem
C # network application programming, experiment 2: IP address translation and domain name resolution exercises