卧薪尝胆,厚积薄发。
      
    
            mode
        
        
        Description:
$n$
个数中某个数出现了超过
$n/2$
次,找出那个数。
$1\le n \le 500000$
 空间限制
$1MB$
Solution:
空间限制
$1MB$
,#include
$<$
iostream
$>$
都不行,更不要说开数组了,既然他出现了超过
$n/2$
次,那么如果每次把两个不同的消掉,最后剩下的就是他,与是只用四个变量统计最后剩下的变量出现的个数即可。
Code:
#include<cstdio>
using namespace std;
int n,t,x,tot;
int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;++i)
	{
		scanf("%d",&x);
		if(tot == 0)
		{
			t = x;tot = 1;
		}
		else if(x == t)++tot;
		else --tot;
	}
	printf("%d\n",t);
	return 0;
}
          In tag:
其他-其他 
          
        
        Copyright © 2020
        
          wjh15101051
        
      
      ღゝ◡╹)ノ♡
    
          Date: Sun Sep 09 19:48:54 CST 2018
          
          In Category:
          
        
            Timeline
          
            About
          
            Toolbox
          
              Friends