Design ideas:
If you delete four different IDs each time, then in the remaining list of IDs, the proportion of the original posting ratio greater than 1/4 is still greater than 1/4, you can get the answer by repeating this process, reducing the total number of IDs in the ID list (into smaller issues).
Program code:
#include <iostream>using namespacestd;voidFindid (intId[],intNintrightid[]);voidMain () {intid[ -] = {1,1,2,2,3,3,3,1,2,3,1,2,3,6}; intn = -; intwaterid[3]; Findid (Id,n,waterid); cout<<"the qualifying IDs are:"<<Endl; for(inti =0; I <3; i++) {cout<< Waterid[i] <<" "<<Endl; }}voidFindid (intId[],intNintwaterid[]) { intFalseid =-1; intnumber[3]; number[0] = number[1] = number[2] =0; waterid[0] = waterid[1] = waterid[2] =Falseid; for(inti =0; I < n;i++) { if(Id[i] = = waterid[0]) {number[0]++; } Else if(Id[i] = = waterid[1]) {number[1]++; } Else if(Id[i] = = waterid[2]) {number[2]++; } Else if(number[0] ==0) {number[0] =1; waterid[0] =Id[i]; } Else if(number[1] ==0) {number[1] =1; waterid[1] =Id[i]; } Else if(number[2] ==0) {number[2] =1; waterid[2] =Id[i]; } Else{number[0]--; number[1]--; number[2]--; } }}
Results:
Personal Summary:
Translating the actual problem into a variable requires a very complex transformation. Although the array is traversed only once, the Number,waterid array needs to be compared many times. This time with the same idea, the 4 different IDs can be eliminated.
Find Water King 2