/ / Www.matrix67.com/blog/archives/tag/% E5% 8D% 9A% E5% BC% 88/page/2
know, pirates gold sub-problem is a very interesting extension. 5 100 gold is not difficult to pirate points, 100 points to 100 pirate gold is not difficult, in fact, points 100 to 200 pirate gold is not a problem. Funny thing happened on the 201 pirate in the body - in order to protect life, he never could get even a piece of gold. He had to have all 100 gold given to the previous odd-numbered 199 individuals who bribe them to vote for him (as in section 200 of the best programs in the pirate what these people are not.) Coupled with her vote total of 101 votes, more than half of the. Similarly, the first 202 to 100 pirate gold must also be given to the first 201 programs pirates who get nothing, bribing them to cast their vote. Since the first program 201 pirates 101 pirates are not anything, so he is no longer the only solution. A total of 101 votes with their votes, exactly half of 202, so that he survived. When the problem extended to N = 203, the situation changed dramatically - 203 die in any case a pirate! Only 100 pieces of gold, not enough to bribe him, he can only get 101 votes in any case (assuming conditions do not forget the pirates in their own title under the same interests will choose to kill more people.) B to B cattle in 204 cow pirate, although he can only bribe to 100 votes, but he actually survived! Guess how he live? Ha ha ha ~ ~ ~ ~ because the first 203 pirates will vote for him anyway, so his words do not vote when their turn over. So the first 204 to 100 gold pirates in the first 202 hours to program the pirates who get nothing, plus 203 and 102 votes their votes, this survived. Similarly, you will find a pirate die 205; Section 206 of piracy, although it will get the support of 205, but still not enough votes; 207 want to live if need 104 votes, but he only got 103 votes; 208 will be 205 , 206,207 of the support, coupled with her vote and bribery to the 100 votes, just live. After the first 216, 232, 264, ..., 200 +2 ^ n a pirate will survive, the game will be their end here.
consider such a double chess game: in a 8x8 square matrix where each fill 1-64 This 64 positive integers. Then A and B two people taking a few turns in the grid, A first take, B taken after. Take the number of rules are simple: take-off can no longer take a few, and except for the first time outside every time you take the number must have been taken off with an adjacent grid. After all numbers are taken, the taking and the largest number of people who win.
Obviously, this game is more favorable for the A number. We can easily construct an initial state, making the first man to take the win. A consideration of such a strategy: always take a few can take the largest one. If every A can be removed that the largest number of board, then A to win the game (because every time the number of B than A to take the next small). This initial state is constructed out of easily, such as we only need to fill it from left to right from top to bottom the number 64 on it, which can guarantee that if all 64 from the number n to have removed the , the n-1 can also be removed.
Now the question is, can construct an initial state, so people have taken after the winning strategy? Tips to resolve This question is need to have super You have to come up with enough ideas to find a bad way to kill a pioneer. Your heart bad enough to solve this problem?
is the key to solve the problem, we give A planted Consider a local construction: an odd number of large numbers connected to each other, these large numbers around the circle all decimals. The figure is a trap, diamonds on behalf of large numbers, and the remaining yellow grid is decimal. A step into a long yellow plaid, and he in terms of: B and A in turn began to take large numbers, but large numbers only odd, so B than in A to obtain the large numbers one more. To make things easier, we consider only the simplest kind of trap: only a large number, around the adjacent lattice are decimal. We have several difficulties: A case of trap outset we supposed to take away the diamonds, but also how to avoid that he will not fall into the trap, and we must ensure that B from the trap to earn enough to make up for in other places loss of. The trap in order to have enough work on the A, we have cloth at least three traps, so that A can trap most earn start, but could not avoid falling into two traps. In order to ensure that he will not fall into the trap, we can board the rest of the domino is divided into (1x2 small rectangular one), so no matter which one to take lattice A, B one can always take the corresponding lattice, not step on the trap. So we thought of following this structure:
we fill in the four traps were 1-2-3-61,4-5-6-62,7-8 - 9-63,10-11-12-64 number of the four groups, each domino fill in the two adjacent numbers. In this case, A's best strategy is to start from the first trap to take a few. He can earn the first trap (61 +2) - (1 +3) = 59 points, but he will lose the other traps (62 +4) - (5 +6) = 55 points (63 +7) - (8 +9) = 53 points (64 +10) - (11 +12) = 51 points. The domino total of only 24, he can only pick up 24 points back, and this is not enough. Therefore, the first take whoever lose.
References: http://www.brand.site.co.il/riddles/200802q.html
combination of such a class game, a game for any situation, the game the legitimate decision-making are exactly the same, the only difference between the two sides battle game is to see who go first. This game is called Impartial Games. What is reported as the number of, ah, ah matches to take, take stone, ah, these games belong to the Impartial Games; and chess, chess pieces and other colors to points of the game do not fall Impartial Games. Shared state of the game almost unplayable, because the game before we will know who is winning (If both sides are using the best strategy). Status of any chess game there are only two, in the face of this chess game are either win or fall. Consider a recurrence relation: if a state is winning state, it moves at least one can walk into a doomed state leave each other; if a state is doomed to failure state, then it can only go how to get win state. The use of this relationship, we can launch from the bottom up, or win the initial state is doomed to failure.
recently been suggested a game called Atropos, it is a difficult to do even if the computer is also Impartial Game, it can ensure the game is still playable. Game on a Sperner triangle, the figure is a side of length 7 Sperner triangle. Start of the game, both sides turn white circle painted in red, green or blue, the color of the circle has been painted can not apply a color. In addition, as long as possible, the circle must be painted next to the last circle that the other painted. Whoever painted the small triangle has three colors, one who will lose this game.
note that this game is not the case a draw. When all the white circles painted all the colors, at least there will be a red, green and blue small triangle. To prove this, we can all draw between green and red circle with an arrow, red arrow on the right in the green of the arrow on the left. These arrows will form a one path, they are neither intersection nor bifurcation.Thus, we found a red, green and blue has a small triangle.
this game though is Impartial Games, but it still has playability. From the intuitive point of view, the upper hand in this game is almost no difference between FLAC, who is not an advantage. Rigorous proof of this thesis to determine the best strategy game Atropos is PSPACE-complete, this is all the problems in polynomial space using a class of the most difficult of all problems with polynomial space can be (in a multi- polynomial time) reduced to it. This shows that, Atropos no obvious game of
online games: http://cs-people.bu.edu/paithan/spernerGame/Sperne rGame.html (Java Applet)
See More: http://cs-people .bu.edu / paithan / spernerGame /
classic primary Orsay Title: Two people take turns on the blackboard write a positive integer no greater than 10. Prohibit the number has been written about the number of write out. Who did not write in the final whoever lost. Q is the first person to write after the writing of people win or win, winning strategy is.
answer is very clever. Were the first to write a winning strategy. He can write down the number 6, now only 4,5,7,8,9,10 can write. The number of the remaining 6 divided into three pairs, namely (4,5), (7,9), (8,10), each of the two numbers are not in a multiple relationship, and their respective times ( If there is ever) must be simultaneous. So no matter what number you write, I write the number on it in another few years, so you can ensure that I always have written.
happened to see an enhanced version of today, I wonder if we've seen is not: the rules change, you can write a few extended to all positive integers less than n. N the first writer to win what? Prove your conclusion.
you have a feel cheated-_-b
In fact, no matter how many n, there is always the first person to write a winning strategy. Consider a new rule If we add the new rules were the first to write a winning strategy, then this strategy also applies to the original game (as the number 1 is all about numbers, did not write); If the new rules were written after the win, the original game first writer wrote the number 1, and then he became a post under the new rules were written. So anyway, those are always the first to write a winning strategy.
To 3 Floor: forgot to mention that, as long as both sides shared state (the legitimate decision-making exactly the same) of the chess game, one party must have a winning strategy. Status of any chess game there are only two, in the face of this chess game are either win or fall. Consider a recurrence relation: if a state is winning state, it moves at least one can walk into a doomed state leave each other; if a state is doomed to failure state, then it can only go how to get win state. The use of this relationship, we can launch from the bottom up, or win the initial state is doomed to failure.
Update: User FreePeter thank the wonderful comments. This analysis method has a very image by the name of Strategy-stealing, it's another classic example is the Chomp game. Game on a rectangle of chocolate, chocolate is divided into MxN blocks. They in turn choose one of the grid, and then eat the box and its right, below and to the lower right corner of all boxes. The upper left corner of that piece of chocolate poisonous, who eat whoever lost. The figure is a possible battle process. We can prove a similar way win the upper hand. Suppose there is a winning strategy FLAC, then handle the lower right corner of that first piece removed. Noted that the other party no matter which steps to take next, the lower right corner of that piece would have also been removed, so there is no change in the chess game, but now the upper hand to play the role of the flip, can be a winning strategy that flac to deal with chess game, this will skillfully
the examples above are the two sides shared the state of the game (ICG game), so there is at least one winning strategy. For other non-ICG games,
true religion billy australia Choi Ji-woo, we can also prove a similar way there can be a winning strategy FLAC (but does not explain here, just get a certain win.) For example, chess game Tic Tac Toe, if flip has a winning strategy, then just get to step lightly, after a subsequent party to pretend to deal with. If you need to just get a step in which the child has been to place Lazi, he then casually step it wants to. This method of proof established the premise that go one step further is certainly not a bad thing. In fact, for all this
in mathematics, the comparison operator is transitive. If A> B, and B> C, then there must be A> C. But in real life is not necessarily the case. Between the three pairs competition, there may be A stronger than B,
cheap ralph lauren, B is stronger than C, but C in turn, won the A. In fact, even if this phenomenon also exists in mathematics. The probability of events in a number of similar
right side of the four dice, respectively A, B, C, D to represent. I will let you select the one you think is the best dice, then I select from one of the remaining three dice. After each of the selected dice throw, the number who throw big, whoever won. Well, you should choose which stars die then?
fact, whether you choose which one dice, the probability of winning is always my major, because the remaining three dice in a dice always better than yours. In fact, four dice, A B is the probability of winning 2 / 3, B C is the probability of winning 2 / 3, C D, the probability of winning is 2 / 3, D won the probability of A or 2 / 3 So no matter which one you choose to die, as long as I choose the one to its left (if you chose the most left, then I choose the right), I always ensure that there are 2 / 3 probability of winning. Do you think such a thing possible? For you do something like this reasonable?
If you do not believe it, we can work together to do the math:
A and B ratio, as long as 4 A throw to win, then A, which is 2 / 3 probability;
B and C than that, as long as C, then B to throw 2 win, which is 2 / 3 probability;
C and D than that, if C throws 6 C must win, if the probability of C winning throw on the other two, so C is the probability of winning (1 / 3) + (2 / 3) * (1 / 2) = 2 / 3;
D and A ratio, if the A throw 0 D must win, if the probability of A winning throw four of the other, D the probability of winning is (1 / 3) + (2 / 3) * ( 1 / 2) = 2 / 3.
Problem: game title to take a few games
Source: Matrix67 adapted according to the classical problem
description of the problem is a selected number of games they play. They will rotate from 1-9 to take the number of the nine figures, the number of take-off can not be taken. We require, who take several years to find three numbers such that the number three and 15, whoever won the game victory. If A took three numbers 1,6,
true religion billy mens,7, B took 2,3,5, if the time to take the number of A, then A = 8 to win, because when A got the number 8, there has been 1 +6 +8 = 15.
each of the game, you can get the game status at this time. Please select a program best strategy to win the game.
input format
first line of input several numbers separated by spaces, that you have to take a number. Increasing order of these numbers.
enter a number of second line number separated by a space that has already taken a number of opponents. Increasing order of these numbers. When a line is not
number (a number of players not selected), the line will still be left out of position.
output format
output you think the time is your best choice.
Sample Input
1 6 7
2 3 5
sample code demonstrates the following code so the game One strategy: each time is not always choose to take the largest number ever.
program game;
var
hash: array [1 .. 9] of boolean;
i: integer;
begin
assign (input, 'game.in');
reset (input);
repeat
read (i);
hash [i]: = true;
until eof;
close (input);
for i: = 9 downto 1 do
if not hash [i] then break;
assign (output, 'game.out');
rewrite (output);
writeln (i);
close (output);
end.
scoring
the subject will be carried out through the round robin between the players score.
two players in a confrontation, the test program into the source of these two players and compiled, and then players take turns to describe the preparation of input files in real time battle situation. Players of the output file will be submitted to the players making up. When the game has emerged the winner or not to continue, the test program ends automatically. Two players per game will be divided into two carried out after a confrontation pioneer will be exchanged. Any of a confrontation, a player wins 2 points, a negative was -2 points, a level was 0 (the score is not a player's final score of the title). After scoring the game ranking, if the total number of players n, your ranking is i, then your score is (n-i +1) * 100 / n. Then remove the entire score as a decimal. The same is equally ranked scoring.
player program the following occurs as negative by the second against the deal:
program single player with more than 1 second run time;
player memory footprint than 64M;
player program does not output decisions or output error;
player program exited;
player evaluation process led to an error program illegal exit.
we have seen, this game is a chess game Tic Tac Toe. 3 add up to 15 the number of a total of 8 kinds of situations, and these 8 kinds of situations happen to correspond to a 3 Magic Fang three transverse and three columns and two diagonals. In other words, think of the game if the board carried out in the following, it is no different, and a chess game Tic Tac Toe.
+---+---+---+
| 8 | 1 | 6 |
+---+---+--- +
| 3 | 5 | 7 |
+---+---+---+
| 4 | 9 | 2 |
+---+---+---+
chess on the Tic Tac Toe game I had before the study.
majored in things like game theory, I once wrote a program to calculate the best strategy game Tic Tac Toe Chess. But no matter how I do, this program always first out the corner of the location, it is very ridiculous. I have been thinking, something which I have a problem with the program. Later, I thought. My program without any problems, but the person out of the habit of thinking wrong. I calculated the results of the program is, in the chess game Tic Tac Toe occupying a corner of the odds start to the maximum.
For example, I now accounts for a position that the bottom left corner. If you go the next step is painting the
+---+---+---+
| X | X | X |
+---+---+--- +
| X | | X |
+---+---+---+
| O | X | X |
+---+---+---+
shown in Figure 1 to Figure 4, the four chess, which includes all except the second step to go beyond the middle of the bifurcation. It can be seen, if you do not occupy the middle of the second step, you are doomed to.
Figure 5 tells us that even opponents occupy the middle, the fourth moves have 2 / 6 traps can kill him. The other 4 / 6 will lead to the ultimate chess game a tie. If each step is random walk, the other side, hit the case of Figure 6,
true religion shorts iphone4 free game download -i, the probability is (1 / 8) * (4 / 6), about 8.33%. In turn, my chance of winning more than 90%. Theoretically, this may be the largest of the.
, of course, the opponent is not stupid. Faced with this situation, the rational man will always want to occupy the middle of the second step the grid. With this in mind, then, the odds may be less than 50%.
careful consideration, you will find, if you first occupied the middle of it, odds are up to 50%. Figure 7 shows such a case, if you take a middle step, and reached the edge of the opponents are not careful, he would be finished. Compared to those who come to the front, where some of the traps may be more subtle.
remaining three graphs show that the opponents away in a corner 4, the final result will be a draw.
As to the selection of so many chess which in the end, this decision is their own.
we consider all the circumstances of his first, but also see itself as a trap that may be encountered after the monk. Control over chess, we can easily obtain the result a draw. Chess Tic Tac Toe game
the total number of the case only so much, not variable, so this thing is a very entry-level things. When the actual writing process, discuss the effect of classification better than the game tree.
Matrix67 original
Links please reference
I am one of the language summer job, asked to write a description of any text.
I am a rookie, full of loopholes within the text, please to submit, thank you enough.
Matrix67 original, reprint, please indicate the source.
recognized recursion (Recursion) standard definition is very hard to understand: If an object contains its own part, or use it to define ourselves, then we say the object is recursive; if a process directly or indirectly call themselves, this process is called a recursive process.
term there have been few professional recursive definition, so this is not to explain the meaning of a text. Although the concept of abstract, but recursion itself is understandable. Through this introduction, the reader can not understand recursion, as long as through specific examples vaguely aware of some of the ideas and use of recursion on it.
What is recursive it? In fact, recursion is the ones devour the small, is a snake biting its tail. Recursion is the thing itself contains its own. For this, take the
curve well understood the concept of geometry is not only the length of the width of the lines. There are a variety of mathematical curves such as circles, straight line, parabola, hyperbola, sine curve. Both methods can be drawn. For example, the circle can be drawn with a compass, the sine curve can also be used on the machine side of the tape edge pull tape back and forth way mark drawn. In fact not so troublesome a curve one of the most commonly used should be able to draw the curve. But with the development of mathematics, which is been questioned. Polish mathematician Shell Pinsky to come up with a really a curve but never be able to draw the graphics. His method of constructing such curves to the use of the recursion.
stuffing a square, put it into the equivalent 3 × 3 size 9 small squares, and then dig up the middle of that one. Now only eight small squares around the. Then repeat the process, the 8 small squares each of which 9 were divided into smaller and dig it the middle of that. Now there is obtained 8 × 8 = 64 squares of the. Continue to do this by 64 squares, and unlimited continues. This is the recursive thinking, including his own, and the back of their own but also contains smaller self. This recursion is poured down, so will end up getting is not the width of the lines. This is consistent with the definition of the curve, but apparently it is no way to draw out.
in real life, the phenomenon of recursion is also possible to see. If a TV screen is showing the camera shoot things, then the camera shot facing the TV set will form a simple recursion. TV show with cameras photographed the contents, then the television cameras, which means that the camera will shoot to shoot their own stuff. Thus, the recursive form - will be shown on a TV layer at the outline of the TV, that TV set, TV, endless layers of the cycle continues. There are some similar examples, such as the never say never-ending story of old, and Linda's second album cover.
recursive infinite loop is usually to go on. So there is such a joke. As an avid fan of computer games, and if one day you place from a complete stranger woke up, how do you determine if this is a virtual space, or in reality? The answer is to find two mirrors, facing each other place. If there is slows down the movement of objects around the abnormal situation, that you are in the virtual space. Nature is amazing, it can handle both sides of the mirror when the mirror should be placed relative to the content displayed; but the computer does not come out on the simulation, this happens if the computer is really, will specify the CPU to death.
However, once a recursive procedure to add a constraint to make it to a step recursion stopped when the words do not continue to cycle, will be useful when recursively.
me give a simple example. Even the number is divisible by 2. I can even use the recursive method definition: an even number with 2 or even number. This sentence seems sufficient to explain all the figures, it is not. Because without any restrictions, this recursive process will be endless, and ultimately will not get any concrete answers. We can add a condition In this way, the situation changed. For example, we see an even-6, according to If 4 is even, then 4 +2 is even. And to see if an even number 4, but also depends on whether it is even 2, depending on whether it is even 2, but also depends on whether 0 is even. Actually, this should be like an infinite recursion to do so, but we have a limitation: we already know that 0 is even. Thus, 2 is even, and 4 and 6 are even a. Similarly, we can determine the parity of all the figures. This is recursive to the mathematical definition.
this definitions are any good? A simple example -
many people do not understand why the factorial of 0 to 1 to the provisions of fact, this used to define a recursive factorial explanation clear.
Factorial can be defined recursively:
1) n factorial is equal to the factorial of n-1 multiplied by n;
2) 1 factorial is 1;
Thus, the factorial of all natural numbers to the above two sentences can be expressed. 2 factorial is 1 × 2; 3 factorial is 2 x 3 factorial, ie 1 × 2 × 3 ... ... Not only that, we can know what is the factorial of 0: 1 factorial factorial should be multiplied by 1 is equal to 0 Obviously, the factorial of 0 must be 1 Caixing. Similarly, we can know that the factorial of negative integer not make sense.
Next, I will use two classical recursive thinking to solve the problem with the example of the end of this article.
French mathematician Eide Wolukasi (Edouard Lucas) in 1883 in a magazine describes a fascinating mathematical puzzle - Tower of Hanoi (Tower of Hanoi), saying it and an ancient Indian legend. Obviously the specific content of the legend has not within the scope of this paper, but I would like to introduce myself.
According to legend, India have a very big temple, it was considered the center of the universe. Place a piece of the temple in the above three long wooden peg inserted in the wood, in which a peg, put the 64 top to bottom in ascending circle diameter metal ring. Ancient Hindu gods instructed his monks to all 64 metal roots on the peg to another. Mobile Rules only two:
1. In each move, can move only one piece of metal;
2. The process of sheet metal must be guaranteed at any time in the small and large the next.
till one day, the monks can 64 pieces of metal by the rules from the specified root peg to another peg on the whole, then, that subsequent to the end of the world, the end of all the world will be destroyed, and all were approaching paradise.
This legend is often considered to promote this, Professor Lucas mathematical puzzle and fabricated, but in any case, Lucas was a success. This thing turned into one of the well-known puzzle game, and later became a required course for learning recursion.
of the Tower of Hanoi Problem focus on how to complete all the steps at least the transfer of sheet metal on this issue. To solve this problem using a recursive thinking.
We think so. 64 metal too much, we seem to be simplified. If we already know how to move the 63, we can put 63 as a whole. Then this process is 64 out of the movement: the first step 63 before moving to another, on the peg; the second step, the first 64 moves to the third root of the peg; the third step, put the 63 back Section 64 above. See? Problem has been solved, because it formed the recursion. We can continue to move 63 of the method is used: to remove the former 62, the mobile section 63, moved back to the previous 62. Continue to study the movement of metal approach 62 ... ... this continues, has been pushed to how to move the two metals. The way to move the two metals is very simple, do not need to continue the discussion, so, all the problems this solution.
found the substance of recursive thinking it? It reminds me of a joke. Joke of the hero is a slow, only a mathematician with mathematical thinking; To make this joke better image, we put this person for the time being as Tongming Guo (Note: my math teacher's name).
Tong Mingguo do firefighters. The captain asked: This light, then the problem is transformed to a problem I've had.
Orsay contact with a school called For example, the first person can apply for 1, also reported that 1, 2; if the first man reported 1,2, the second to be reported 3 and 3,4; then the first person and reported; this report continues, the first report of 30 people to win.
very boring game, because it has a winning strategy.
won the first report of 30 people, apparently, the first report of 27 people will be able to win; then, the first report of 24 people will certainly win the ... ... recursion continues, 21,18, end up The conclusion is that the person must first win 3 report. In other words, those who reported after the win. No matter who first reported that the number reported, after the newspaper report are always a multiple of 3, so that will be able to win.
there are many variants of this game, but the new name, original aim. For example, the rules changed to Thus, the first report of 29 people will win, then the same recursive, 26,23,20 ... ...
saw online a few days before the game, a difficult variant.
10 coins, each in turn take coins, you can take one, two or four; get to the last coin wins.
so there winning strategy? The answer is yes, but the idea can also use recursion to solve.
If the total number of only one coin, the first take they win;
is two if the total number of coins, the first take they win;
is three if the total number of coins pieces, the first taker input;
if the total number of coins is four, the first taker win;
If the total is five coins, the first taker win (take two, the other the situation facing the three, will lose);
if the total number of coins is six, then lost the first taker (whether to withdraw, the situation facing each other are a winning situation);
If the total is seven gold coins, the first take they win (to take one, the other face six of the case, losing);
If the coin is the total number of eight, who won the first take (to take two gold, the other face six of the case, losing);
if the total number of coins is nine, then lost the first taker (whether to withdraw, the situation facing the other side is winning the case);
If the total is ten coins, the first take they win (to take one, the other faces nine of the cases, will lose.)
(this reference: This article Oh)