Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Hi I came across this question from my friend.
Give me a generalised formula to find how many tennis matches (singles) are required for n players ?
Example : if the number of players are 16 then
first : we need 8 mataches (for 16 players) , here 8 players will be eliminated and 8 players will be there
secode : we need 4 matches (for 8 players) , here again 4 players will be eliminated and 4 will be remaining
third :
we need 2 matches (for 4 players) , here again 2 players will be eliminated and 2
will be remaining
Final :
we need 1 macth to decide a winner among the 2 players
so totally 15 matches are required.
I need a generalised formula to find , such that if I give the value n I should get the number of matches required to find the winner
n may be odd or even
For elimination game, the number of matches is always n-1, because one player will be eliminated after one game and n-1 players have to be eliminated in total.
As eventually every player but 1 (the champion) has to lost his match (and every player can lost only in 1 match) then the number of matches required is n-1
n-1, because there is one player to leave after each game. and the champion remains
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I came across the following question: What is the smallest number n by which the given number x must be divided to make it into a perfect square?
n = find_number ( x )
I know the standard way to do this to find the prime factors of x and multiple by what is necessary to have perfect squares in the prime factors, but I saw this answer:
The number is 1/x so x/1/x= x^2
Not sure if that it completely wrong, or is a genius and direct solution
Thanks
no thats not correct ...
for 2 you say its 1/2 then 2 / (1/2) is 4 which is perfect square cool
but what about 1/8 then 2 /(1/8) is 16 which is perfect square
and 1/8 < 1/2 so thats one contradiction you need to know that thats not correct
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Here is a sequence of integers
a1, a2, ... an, 1<=ai<=100 2<=n<=100.
The sequence of integers are arranged in non-decreasing order.
m(2<=m<=4) players take turn to choose one of these integers to tag. If an integer is tagged twice, it's occupied by the player who chose it last, and the player gets another chance to tag. (Obviously, the integer can't be tagged the third time:) )
The sum of the integers the player occupies is the player's final score. The player with the highest score wins. As these players all play with their best strategies, decide which one will win according to the sequence of integers.
Looks like an ACM-ICPC problem? Not really. It's really a game:)
EDIT
The players can't pass their turns.
Reason being, a player would like to pass a turn only if he/she has no incentive to play that turn. So if player i passes a turn, then any other player j would also see that they have no incentive to play that turn. So they would also end up passing the turn and the game gets stalled forever.
For example, the sequence is 1,2. 2 players are playing. The first one tagged 1, and the second tagged 1 too, so player2 got 1 point. Then player2 got another chance to tag, 1 can't be tagged, so he tagged 2. Now it's player1's turn, he can only tag 2, and he will get 2 points after he tags 2. After this game, player1 gets 2 points while player2 gets 1. So player1 wins.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am trying to figure out a way to figure out how many times an even number can be divided by two before it becomes odd. I.E. 100/2 = 50 => 50/2 = 25. So 100 can be divided by two twice. before it becomes odd. I am looking for all even numbers that are NOT powers of two.
That's two questions.
I am trying to figure out a way to figure out how many times an even number can be divided by two before it becomes odd. I.E. 100/2 = 50 => 50/2 = 25. So 100 can be divided by two twice. before it becomes odd.
Convert the number binary and count the 0s before the first 1. Each time you dive by 2 you loose a zero and when a 1 is in the "first" position you've got an odd number.
I am looking for all even numbers that are NOT powers of two.
Again, looking at the binary, powers of 2 have only one bit set and odd numbers have the 1 bit set. So anything with multiple bits set AND not the 1 bit is your answer.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
The original question is:
Describe an algorithm to output a die roll(a random number from 1 to 6), given a function that outputs a coin toss(a random number from 1 to 2). Each possible outcome should be equally likely.
The most popular answer to this question is:
Flip the coin three times, and use the three coin flips as the bits of a three-bit number. If the number is in the range 1 to 6, output the number. Otherwise, repeat.
My question is:
Most of the discussions on Stack Overflow come in the above flavour. I've also searched the Internet, finding that there exist many answers of other flavours, which they don't explicitly dig into. Could someone please share one or two different ideas on this problem?
There is a small improvement to the "toss 3 times and discard if 110 or 111" algorithm. Discarding 110 or 111 is wasteful, since you are wasting one perfectly good bit of entropy that you could reuse. After one of these values pops up, you only need to toss twice and get the value of the third toss from the mapping {110->tails, 111->heads}. Both of 110 and 111 are equally probable, so you're not introducing any bias this way.
In pseudocode:
bit0 = toss()
while True:
bit1 = toss()
bit2 = toss()
if bit1,bit2,bit3 give i such that 0<=i<=5 then
return i+1
else
bit0 = bit3 // the reuse happens here
The expected number of tosses here is 1 + 2 * expected_number_of_loop_executions = 1+2*8/6 = 11/3
If you just want other options, not necessarily good ones then how about this:
Flip a coin for each possible output value.
If there is one or more heads then discard all the possible values that got tails.
If you have only one value left then stop. Else goto 1.
I would suspect it is going to have a higher expected number of coin tosses than the method you've described and have no advantages at all really.
In general I assume this is why there is not much on the other possible ways of using random numbers. They are just not as good.
Flip 5 coins. If they're all heads or all tails, your answer is 1. If there's only one head or one tail, continue to the next step. If there's more than one head and more than one tail, repeat this step (including reflipping the coins).
Flip 4 coins. If they're all heads or all tails, your answer is 2. If there's only one head or one tail, continue to the next step. If there's two heads and two tails, repeat this step (including reflipping the coins).
Flip 3 coins. If they're all heads or all tails, your answer is 3. Otherwise, continue to the next step
Flip 2 coins. If they're both heads, your answer is 4. If they're both tails, repeat this step (including reflipping the coins). Otherwise, continue to the next step.
Flip 1 coin. If it's heads, your answer is 5. If it's tails, your answer is 6.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
hi to all
I want to know how to find the solution for this problem. consider in a Jar there are 10 papers numbered 1 to 10. we have to take 2 papers from that. what is the probability that 2 numbers are consecutive numbers.
It's a probability to choose one of 9 consecutive pairs from C(10, 2) possible pairs. Thus its 9 / (10*9 / 2) = 1 /5
The probability of getting 2-8 is 8/10. Once we have a given number in that range, the probability of getting one of the two adjacent numbers is 2/9. 8/10 * 2/9 = 16/90.
The probability of getting either a 1 or a 10 is 2/10. If we have one of those two endpoint numbers, the probability of getting the one adjacent number is 1/9. 2/10 * 1/9 = 2/90.
Adding these together, we have a total probability of 18/90 or 1/5.
Your first choice has ten possible numbers. 8 of those 10 will have two consecutive numbers, while the other two only have 1. Your second choice will be out of nine numbers. So
(8/10 * 2/9) + (2/10 * 1/9) = 9/45 = 1/5