当前位置:网站首页>Sequence table - find main element
Sequence table - find main element
2022-06-13 00:48:00 【Feiyichai】
Examples of kingcraft : As efficient as possible , Find the main element
Because it is required to be as efficient as possible , So we use the time for space algorithm , Set up an auxiliary array , Its capacity is the maximum in the sequence , Count their appearance times , If it meets the requirements, output .
#include<stdio.h>
#define MAXSIZE 100
int main(){
// Find the main element
int a[] ={
0,3,3,3,3,7,5,5};
int temp[MAXSIZE];
int max=a[0];
int i;
for(i=0;i<9;i++){
// Find the maximum value of the sequence
if(max<a[i])
max=a[i];
}
printf("%d ",max);
for(i=0;i<max;i++){
// Auxiliary array timer initialization
temp[i]=0;
}
for(i=0;i<9;i++){
temp[a[i]]++;// Statistics
}
int t=0;
for(i=0;i<max;i++){
if(temp[i]>=n/2){
t=i;// Main element found
break;
}
}
if(t!=0)// Output main element
printf("%d",t);
}
边栏推荐
- Druid reports an error connection holder is null
- Mongodb array operation
- 硬(磁)盘(二)
- Learning and Development notes of mongdb
- Influence of higher order poles on waveform
- [JS] solve the problem that removeeventlistener is invalid after the class listening event from new is bound to this
- BUUCTF之BabyUpload[GXYCTF2019]
- 阿姨学代码续集:能力吊打大批程序员
- Today's sleep quality record 74 points
- MCU serial port interrupt and message receiving and sending processing -- judge and control the received information
猜你喜欢
Canvas game 2048 free map size
Target recognition gadget
[MRCTF2020]Ez_bypass --BUUCTF
Today's sleep quality record 74 points
Antdpro - protable realizes the linkage effect of two selection boxes
In / out / inout details of MySQL stored procedures
Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis
Kotlin coroutine withcontext switch thread
Kotlin collaboration, the life cycle of a job
Maybe we can figure out the essence of the Internet after the dust falls
随机推荐
Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
Make the tasks in the scheduled task XXL job flexible
Mongodb array operation
The seventh finals of the Blue Bridge Cup
Androi weather
Leetcode weekly -- April to May
1. Google grpc framework source code analysis Hello World
[gxyctf2019] no dolls -- detailed explanation
JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception
Paper reading and sharing
BUUCTF之BabyUpload[GXYCTF2019]
Programming training 1
高阶极点对于波形的影响
[JS component] calendar
Download nail live playback through packet capturing
Assembly language learning
ROS2之OpenCV人脸识别foxy~galactic~humble
Browser console injection JS
Aof persistence
硬(磁)盘(二)