Looking for an extension to the "Water King" issue: "Super Water King" is gone. Statistical results show that there are 3 posts a lot of IDs, their number of postings are more than the total number of post n 1/4. Can you quickly find their ID from the list of post IDs?
(i) Analysis of the problem:
If you delete four different IDs at a time (regardless of whether or not they contain more than 1/4 of the total number of posts), then in the remaining list of IDs, the proportion of the original posting ratio greater than 1/4 is still greater than 1/4, which can be repeated by repeating the process, Reduce the total number of IDs in the ID list (into smaller issues) to get answers to the questions
(b) Code implementation:
PackageFind the king of the waters;PublicClassXiaoshuiwang {Staticvoid Find (int id[],int N,IntCandidate[]) {int ntimes[]={0,0,0};Forint i=0;i<n;i++) {if (id[i]==candidate[0]) {ntimes[0]++;}Elseif (id[i]==candidate[1]) {ntimes[1]++;}Elseif (id[i]==candidate[1]) {ntimes[2]++;}Elseif (ntimes[0]==0) {Ntimes[0]=1; candidate[0]=Id[i]; }Elseif (ntimes[1]==0) {Ntimes[1]=1; candidate[1]=Id[i]; }Elseif (ntimes[2]==0) {Ntimes[2]=1; candidate[2]=Id[i]; }Else{ntimes[0]--; ntimes[1]--; ntimes[2]--; }} System.out.println ("Three qualifying IDs are respectively");for (int i=0;i<3;i++ public static void< Span style= "color: #000000;" > Main (String args[]) {int id[]={1,1,1,2,2,2,3,3,3,1,2,3,1,2,3,6}; int n=16int candidate[] = { -1,-1,-1); for (int i=0;i<n;i++
(iii) Experiments:
Looking for a small aqua king