From 693f8de8fe08b11db3c4ed5f1190f90dacbaa0db Mon Sep 17 00:00:00 2001 From: LTF <39181832+SDLTF@users.noreply.github.com> Date: Mon, 4 Jan 2021 18:53:32 +0800 Subject: [PATCH] Update and rename mainelement to main-element --- docs/misc/{mainelement => main-element} | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename docs/misc/{mainelement => main-element} (91%) diff --git a/docs/misc/mainelement b/docs/misc/main-element similarity index 91% rename from docs/misc/mainelement rename to docs/misc/main-element index b9f82a2b..833b7cbb 100644 --- a/docs/misc/mainelement +++ b/docs/misc/main-element @@ -1,9 +1,10 @@ -作者:``SDLTF`` +author: SDLTF ## 概述 给一个有$n$个元素的数列,保证有一个数$a$出现的次数**超过**$50%$,求这个数。 -## 做法1:桶计数做法 +## 做法 +### 桶计数做法 桶计数做法是出现一个数,就把这个数出现次数+1,很好懂: ```cpp for(int i = 0;i < n;i ++){ @@ -21,17 +22,19 @@ for(int i = 0;i < 10001;i ++){ 但是这个做法很浪费空间,我们不推荐使用。 -## 做法2:排序做法 +### 排序做法 显然,若一个数列存在主元素,那么这个主元素在排序后一定位于$\frac{n}{2}$的位置。 + 那么我们又有想法了: ```cpp sort(a, a + n); cout<