标签:ott mit eof int cat lines ast return input
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1029
题目类型:
给一个奇数个列的数组,其中一定存在某个数字,该数字的个数是大于一半的,问这个数字是几
解题思路:
1、sort一遍,直接输出下标为n/2的数。
2、将数组开为1000010,然后将数组置0,读入一个数,下标为该数的数值+1,最后进行一次循环,判断那个数值最大,输出即可。(当年还不会快排所以用的这个方法,亲测AC)。
题目:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 31704 Accepted Submission(s): 13646
# 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; }
hdu-1029 Ignatius and the Princess IV
标签:ott mit eof int cat lines ast return input
原文地址:http://www.cnblogs.com/love-sherry/p/6941505.html