Find the Water King 2

Source: Internet
Author: User

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

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.