日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu-1029 Ignatius and the Princess IV

發布時間:2025/7/14 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu-1029 Ignatius and the Princess IV 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:

http://acm.hdu.edu.cn/showproblem.php?pid=1029

題目類型:

給一個奇數個列的數組,其中一定存在某個數字,該數字的個數是大于一半的,問這個數字是幾

解題思路:

1、sort一遍,直接輸出下標為n/2的數。

2、將數組開為1000010,然后將數組置0,讀入一個數,下標為該數的數值+1,最后進行一次循環,判斷那個數值最大,輸出即可。(當年還不會快排所以用的這個方法,親測AC)。

題目:

Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 31704????Accepted Submission(s): 13646


Problem Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.

"But what is the characteristic of the special integer?" Ignatius asks.

"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.

Can you find the special integer for Ignatius?

?

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

?

Output For each test case, you have to output only one line which contains the special number you have found.

?

Sample Input 5 1 3 2 3 3 11 1 1 1 1 1 5 5 5 5 5 5 7 1 1 1 1 1 1 1

?

Sample Output 3 5 1

?

# include <stdio.h> # include <string.h> # define N 1000010 int n,a[N],b[N];int main () {int i,ret,max;while(scanf("%d",&n)!=EOF){memset(b,0,sizeof(b));max=0; ret=0;for(i=0;i<n;i++){scanf("%d",&a[i]);b[a[i]]++;if(b[a[i]] >max){max=b[a[i]];ret=a[i];}}printf("%d\n",ret); }return 0; }

?

轉載于:https://www.cnblogs.com/love-sherry/p/6941505.html

總結

以上是生活随笔為你收集整理的hdu-1029 Ignatius and the Princess IV的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。