"Algorithm Series learning" [Kuangbin you fly] topic 12 Basic DP1 B-ignatius and the Princess IV

Source: Internet
Author: User

Http://www.cnblogs.com/joeylee97/p/6616039.html


With the introduction of a CNT, the INPUT element is the same as the previous element, CNT increases, otherwise CNT decreases, when CNT is zero, the input element is recorded, because the desired number appears at least (n+1)/2 times, so the last recording element is the element that is being asked for

1#include <iostream>2#include <cstdio>3#include <string>4#include <cstring>5#include <cmath>6#include <algorithm>7 8 using namespacestd;9 Const intmaxn=1e6+Ten;Ten  One intN; A intMain () - { -      while(SCANF ("%d", &n)! =EOF) the     { -         intTemp,cur,cnt=1; -scanf"%d",&temp); -          for(intI=1; i<n;i++) +         { -scanf"%d",&cur); +             if(cur==temp) A             { atcnt++; -              }  -              Else -              { -cnt--; -              } in              if(cnt==0) -              { totemp=cur; +Cnt=1; -              } the              *         }     $printf"%d\n", temp);Panax Notoginseng     } -     return 0; the}
View Code

"Algorithm Series learning" [Kuangbin you fly] topic 12 Basic DP1 B-ignatius and the Princess IV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.