Find a post water King 01

Source: Internet
Author: User

Design ideas:

Each time you remove two different IDs from the ID list, it does not affect the fact that the water King's ID is still more than half the remaining ID, so every time you delete two different IDs until all the remaining IDs are the same, then the ID of the water king remains.

Specific implementation:

For specific programming, use a candidate to record the current guessed water King ID, a count to record its cumulative number, and then traverse the entire ID list, for the currently examined ID, if and candidate the same, then count++, if different, then count--, This "count--;" The action is "delete two different IDs" in the embodiment of the program, when Count==0, then update candidate. So, each time count--is equivalent to delete two different IDs (may contain water king, may not contain), and each visit an ID, either will do count--action, or will do count++ action, both will be one, and because "water King ID more than half" the fact that So the number of count--must be less than count++, so the last count must be a positive integer, and at this time the candidate must record the water King's ID.

Find a post water King 01

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.