JOJ 1119 1121

Source: Internet
Author: User

Job 1119: Number Game

Question: http://acm.jlu.edu.cn/joj/showproblem.php? PID = 1, 1119

The rule for two people to take the number in turn is as follows: the number that has already been obtained cannot be obtained; the number that has already been obtained cannot be a multiple; the number that cannot be obtained and the same cannot be obtained. If it is the turn of a person to take the number, there are countless merits, then the game is lost. Now, we will provide a list of currently available numbers and ask which number should be used to win. If there are more than one such number, we will output all of them. If there is no such number, then an unsolvable message is output.

The list of currently available numbers is provided. One idea is to take every number away and see what the outcome will be, so it is a common DFS. The status of each node in the search tree is the current game situation (that is, the list of currently available numbers). The game players will certainly take the most favorable step for themselves, therefore, if there is a number in the current situation, and the rest of the situation will be defeated after it is removed, the current situation will win. If such a number does not exist, the current situation is a defeat. Currently, the absence of a number is a result of defeat.

If you draw a search tree, you will find many overlapping sub-problems. Therefore, you can save the conclusion by using the memorandum of dynamic planning. The data size in the question cannot exceed 20, so it is advisable to use the I-Bit of an integer to represent the number I.

 

Joj 1121 false coin

Question: http://acm.jlu.edu.cn/joj/showproblem.php? PID = 1, 1121

One of the n coins is unqualified and may be light or heavy. A balance can tell the relative relationship between the two coins. Give K weighing results, write the program to calculate which coin is unqualified, if not sure, output 0. the coin is numbered from 1. For example, if the first weighing is 1 to 3 light, and the second weighing is 2 to 3 light, 3 is definitely unqualified.

Solution: There is no idea to find a general method to derive the unqualified coin from the inequality. From another angle, the problem starts from the result and the result is that a coin is found to be bad or uncertain (in this case, more than one coin may be bad ). However, a coin of "A coin is bad" may be any of n coins, so you can use the exhaustive method to eliminate them one by one. How can a coin be ruled out? The title says that only one coin is bad, so we can assume that the weight of other coins is 1 at this time, and the weight of the bad coin may be smaller than 1 or larger than 1, let it be 0 and 2 respectively, and then verify whether the inequalities are true. If all the inequalities are true, the coin is bad. Otherwise, the coin is qualified. In this process, the number and number of bad coins are recorded, and all coins are exhausted. If there is only one bad coin, output its number, more than one, and output 0.

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.