当前位置:网站首页>11 wrong set
11 wrong set
2022-07-27 11:09:00 【DHU yanghualin (UV allergy)】
11 The wrong set
author : Turbo The time limit : 1S chapter : curriculum design
Problem description :
aggregate s Contains from 1 To n The integer of , And in ascending order . Unfortunately , Because of the wrong data , Causes one number in the set to be copied to another number in the set , Results in a collection Lost a number also There's a number that repeats .
Given an array nums For the assembly S The result of an error .
Please find out the repeated integers , And find the missing integer .
Example 1:
Input :
4
1 2 2 4
Output :
2 3
Example 2:
Input :
2
1 1
Output :
1 2
Enter description :
Enter two lines :
The first line is an integer n Representative array nums The length of .
Second line input n An integer represents an array nums The elements of .
Tips :
2 <= n <= 10^4
1 <= nums[i] <= 10^4
The output shows that :
Output a line of two integers to represent the result , Integers are separated by spaces . The first represents a recurring integer , The second represents the missing integer .
Input example :
5
1 1 3 4 5
Output example :
1 2
Possible array encoding And serial number set in set It's a little hard to understand In fact, to put it simply Also used the knowledge of hash table ( An auxiliary array is used haxiarr To record Data and his arr Put a mark on )
The following is true AC Code
#include<iostream>
#include<algorithm>
using namespace std;
struct haxi
{
int total = 0;
int data1 = 0;
int data2 = 0;
int number1 = 0;
int number2 = 0;
};
bool cmp(haxi x, haxi y)
{
return x.total > y.total;
}
int main()
{
int n = 0;
cin >> n;
int arr[10001];
haxi haxiarr[10001];
for (int i = 0; i < n; i++)
{
cin>>arr[i];
if (haxiarr[arr[i]].total > 0)
{
haxiarr[arr[i]].data2 = arr[i];
haxiarr[arr[i]].number2 = i;
haxiarr[arr[i]].total++;
}
else
{
haxiarr[arr[i]].data1 = arr[i];
haxiarr[arr[i]].number1 = i;
haxiarr[arr[i]].total++;
}
}
sort(haxiarr, haxiarr + 10000, cmp);
if (haxiarr[0].data2 < arr[haxiarr[0].number2 - 1])// For example
//1 1 3 4 5
{
cout << haxiarr[0].data1 << " ";
cout << ++arr[haxiarr[0].number2 - 1] << " ";
}
else if(haxiarr[0].data2>arr[haxiarr[0].number2-1])
//1 2 3 6 5 6 7 8 9 10
{
cout << haxiarr[0].data1 << " ";
cout << ++arr[haxiarr[0].number1 - 1] << " ";
}
else if (haxiarr[0].data1 == arr[haxiarr[0].number2 - 1])
{
cout << haxiarr[0].data1 << " ";
cout << ++haxiarr[0].data1 << " ";
}
return 0;
}
边栏推荐
- Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?
- 计算重叠积分的第二种方法
- tf.AUTO_ Function of reuse
- Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
- Local and overall differences between emergence and morphology
- 【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
- Using skills of word
- Pyqt5 rapid development and practice 4.2 QWidget
- [FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
- Cancer DDD
猜你喜欢

One stop monitoring of the software and hardware infrastructure of the whole university, and Suzhou University replaces PostgreSQL with time series database

Non progressive phenomena of entropy and morphology

Derivation of the detailed expansion sto overlap integrals

Li Hongyi_ Machine learning_ Assignment 4 (detailed explanation)_ HW4 Classify the speakers

The difference of iteration number and information entropy

The second method of calculating overlapping integral

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

Recruit top talents! The "megeagle creator program" of Kuangshi technology was officially launched

An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft

Record of a cross domain problem
随机推荐
Learning C language together: structure (2)
YonBuilder赋能创新,用友第四届开发者大赛“金键盘奖”开启竞逐!
antd table+checkbox 默认值显示
SQL Server2000 database error
The open source project Taier version 1.1 was officially released, and the list of new functions is fast
MySQL installation (RPM package)
Overview of data security in fog computing
深度解析:什么是Diffusion Model?
Wilderness search --- search iterations
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
The difference between scalar, vector, matrix and tensor in deep learning
Deep analysis: what is diffusion model?
Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis
如何组装一个注册中心
Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
Solved syntaxerror: (Unicode error) 'Unicode scape' codec can't decode bytes in position 2-3: truncated
Ansible
Kangaroo cloud stack based on CBO in spark SQL optimization
[QNX Hypervisor 2.2用户手册]9.9 logger
Background color style modification on table hover in antd