HDU 1029 Ignatius and the Princess IV

Source: Internet
Author: User

Test instructions: Find out the number of occurrences greater than (n+1)/2.

Idea: Open a one-dimensional array dp[0000]---Array matches the number of occurrences

For example:

5

1 2 1) 1 7

DP[1] = 3;

Dp[2]= 1;

DP[7] = 1;

#include <stdio.h>int dp[1000000];//100, initialized to 0int main () {    int n=0,temp = 0,i,yes;    while (scanf ("%d", &n)!=eof) {        //Initialize for        (i=0;i<1000000;i++) {            dp[i]=0;        }        for (i=0;i<n;i++) {            scanf ("%d", &temp);            dp[temp]++;            if (dp[temp]>= (n+1)/2) {                yes=temp;//tag            }        }        printf ("%d\n", yes);    }    return 0;}








Ignatius and the Princess IV Ignatius Matthews and four princesses
Time limit:2000/1000 MS (java/others) Memory limit:65536/32767 K (java/others)
Total submission (s): 20766 Accepted Submission (s): 8574


Problem Description "OK, you aren't too bad, em ... But can never pass the next test. "Feng5166 says.
"Well, you're not too bad for them ... But you can never pass the next exam. "Feng5166 said.
"I'll tell you a odd number N, and then N integers. There will is a special integer among them, "I'll show you an odd n and then n integers." There is a special integer between the n number,
You have a to-tell me which integer was the special one after I tell you all the integers. "feng5166 says.
Your goal is to find the position of this integer. "Feng5166 said.
"What's the characteristic of the special integer?" Ignatius asks.
"But what are the characteristics of special integers?" Ignatius Matthews asked.
"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.
"This integer appears at least (n+1)/2 times. If you can't find this integer, I'll kill the princess and you'll be my dinner. Ha ha... "Feng5166 said.
Can you find the special integer for Ignatius?
Pro ~ Can you help Ignatius find this whole number?
Inputthe input contains several test cases. Each test case contains the lines. The input data will contain more than one. Each test case will have two 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 first row is an odd number, the second line contains the N integers. The input is terminated by the end of file.
Then the second line has n number. When the input data arrives at the end of the file, indicates that the input ends.
Outputfor each of the test case and you had to output only one line which contains the special number you had found.
For each test case, output this particular number on a separate line.
Sample Input
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1

Sample Output
351

Authorignatius.l

HDU 1029 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.