当前位置:网站首页>10 complete half of the questions
10 complete half of the questions
2022-07-27 11:09:00 【DHU yanghualin (UV allergy)】
This problem needs to use t Knowledge of hash tables , First, the hash table is a hash table Also known as hash table He and adjacency table are not the same thing But they are all done in the form of tables . Don't confuse them .
Then let's take a look at what a hash table is Students who didn't attend online classes before Now listen Take you to quickly understand Hashtable ( Hash table ) How it works _ Bili, Bili _bilibili
10 Complete half of the topic
author : Turbo The time limit : 1S chapter : curriculum design
Problem description :
Yes N A friend participated in the 「 To make friends 」 Offline activities . The sponsor provided 2*N questions , integer array questions Each number corresponds to the type of knowledge points involved in each topic .
If each friend chooses a different question , Please return to the selected N How many types of knowledge points does the topic contain at least .
Example 1:
Input :
4
2 1 6 2
Output :1
explain : share 2 Wei Keyou , stay 4 Choose from the questions 2 topic .
The type of knowledge points can be selected as 2 I'm not sure , At this time, there is only one knowledge point type , So at least 1 There are three types of knowledge points .
Example 2:
Input :
12
1 5 1 3 4 5 2 5 3 3 8 6
Output :2
explain : share 6 Wei Keyou , stay 12 Choose a topic from the following questions , Need to choose 6 topic .
3 The type of knowledge points for bit selection completion is 3 The subject of ,3 The type of knowledge points for bit selection completion is 5 The subject of , So at least 2 There are three types of knowledge points .
Enter description :
Enter two lines :
The first line is an integer n Representative array questions The length of ,n=2*N,N Is the number of friends .
Second line input n An integer represents an array questions The elements of .
Tips :
2 <= n <= 10^5
1 <= questions[i] <= 1000
Output an integer to represent the result .
Input example :
6
1 2 3 4 5 1
The output shows that :
2
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int x, int y)
{
return x > y;
}
int main()
{
int arr[100001] = { 0 };
int haxi[100001] = { 0 };
int n = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
haxi[arr[i]]++;
}
int people = n / 2;
sort(haxi, haxi+1000,cmp);
int total = 0;
for (int i = 0; i < 1000; i++)
{
if (people > 0)
{
people -= haxi[i];
total++;
}
else
{
break;
}
}
cout << total << endl;
return 0;
}边栏推荐
- 荒野觅踪---寻找迭代次数
- 树形数据转换
- C language 2: find the maximum value of three numbers, find the middle value of three numbers, and write program steps
- 如何创建一个带诊断工具的.NET镜像
- c语言指针函数和函数指针的辨析
- Solved syntaxerror: (Unicode error) 'Unicode scape' codec can't decode bytes in position 2-3: truncated
- Record of a cross domain problem
- Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis
- Application of 5g private network in smart medicine
- [QNX hypervisor 2.2 user manual]9.9 logger
猜你喜欢

Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)

Use of parsel

Want to speed up the vit model with one click? Try this open source tool!

How to assemble a registry

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

迭代次数和熵之间关系的一个验证试验

华硕无双,这可能是屏幕最好的平价高刷轻薄笔记本

img src为空或者src不存在,图片出现白色边框

Internal and external troubles of digital collection NFT "boring ape" bayc

图片中非0值的数量对分类的影响
随机推荐
Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
Object array de duplication
Kgdb debug kernel cannot execute breakpoints and kdb-22:permisson denied
Detailed explanation of status code meaning
Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
Tensorflow notes - basic functions and concepts
ECCV 2022 | 同时完成四项跟踪任务!Unicorn: 迈向目标跟踪的大统一
Pyqt5 rapid development and practice 4.2 QWidget
Yiwen counts NFT projects valued at more than US $100million
黑白像素分布对迭代次数的影响
How to create a.Net image with diagnostic tools
Symmetric encryption and asymmetric encryption
学习笔记-微信支付
TensorFlow张量运算函数集
TensorFlow笔记——基本函数及概念
BeautifulSoup的使用
Antd table+checkbox default value display
A measurement method of 5g air interface one-way delay and its reliability