Observations:

  • All algorithms that are removed from the vote have the same number of votes, which is the second highest number of votes if there are multiple highest votes.
  • If an algorithm gets all the votes in a round, then the voting ends.
  • Initially, the highest number of votes is 'm' (all algorithms are present).
  • In the next round, there will be less than or equal to ⌈n/2⌉ votes.
  • If the number of remaining votes becomes less than the highest votes in the previous round, then the voting ends.

Proof:

  • Let's say we have 'k' algorithms left, and all have the same number of votes 'v'.
  • At each round, the number of votes decreases, so it will eventually reach 'v'.
  • Now, let's consider the case when there are multiple highest votes in a round.
  • In this case, all algorithms will be removed, and the number of options will decrease.
  • The new highest votes will be less than the previous highest votes.
  • So, the number of votes will decrease at each round until it becomes less than the previous highest votes.
  • If the number of votes is less than the previous highest votes, then the highest votes cannot be achieved again, and the voting ends.

Plan:

  • If 'n=1', then the voting ends in the first round.
  • Otherwise, the voting continues until there is only one algorithm left or the number of votes becomes less than the previous highest votes.

Complexity: O(T*log(N)), where 'T' is the number of test cases and 'N' is the maximum value of 'm'.

Note: A simpler implementation would be to keep track of the previous highest votes. But since the number of votes decreases at each round, we can just compare the current votes with the previous highest votes.

Determine if Voting Process for Algorithm Selection Will End

原文地址: http://www.cveoy.top/t/topic/nQlC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录