Dynamic planning: Ignatius and the Princess IV

Source: Internet
Author: User

#include <stdio.h>#include<string.h>#include<math.h>intMain () {_int64 n,a;  while(SCANF ("%i64d", &n)! =EOF) {_int64 B=0, C;  while(n--) {scanf ("%i64d",&a); if(b==0) {C=A; b++; }            Else            {                if(c==a) b++; Elseb--; }} printf ("%i64d\n", c); }    return 0;}

Problem Description "OK, you aren't too bad, em ... But can never pass the next test. "Feng5166 says.
"I'll tell you a odd number N, and then N integers. There'll be a special integer among them and you've to tell me which an integer is the Special one after I tell you all the integers. "feng5166 says.
"What's the characteristic of the special integer?" Ignatius asks.
"The integer would appear at least (n+1)/2 times. If you can ' t find the right integer, I'll kill the princess, and you'll be my dinner, too. Hahahaha ... "feng5166 says.
Can you find the special integer for Ignatius?

Inputthe input contains several test cases. Each test case contains the lines. The first line consists of an odd integer N (1<=n<=999999) which indicate the number of the integers feng5166 would te ll our hero. The second line contains the N integers. The input is terminated by the end of file.

Outputfor each of the test case and you had to output only one line which contains the special number you had found.

Sample Input51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1

Sample Output351

Dynamic planning: Ignatius and the Princess IV

Related Article

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.