Probability and stat [closed] - probability

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
A group of eight people decide to use the “Secret Santa” method so that each person buys another one a Christmas present. To this end, each writes their name on a piece of paper, and all names are placed in a hat. Then, each person draws a piece of paper from the hat. If someone draws their own name, all names are placed back in the hat, and drawn again, until success.
What is the probability that the method succeeds with just one draw? In other words, what is the probability that no one draws their own name in just one draw?

With n people,
The probability of not drawing your own name is
(n-1) / n
The probability of n people not drawing their own names is
((n-1) / n)^ n
But that's only if you put the names back into the hat after they're drawn.
If you don't put the names back, which would be the real world example, it would be
((n-1)/n)) * ((n-2)/(n-1)) * ((n-3)/(n-2)) * etc * (1/2)

Related

How to make snake game with random walls appearing? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I almost wrote a snake game, but I still can’t get one of the main ideas.
I would like for random walls to appear on the map during the game, as it happens in google snake game in wall mode. Here is the link to game.
My question is only about the idea of ​​the algorithm and it's disconnected from a specific programming language.
The problem is that absolutely random walls could create “unreachable” places in the level, such as enclosed spaces, where the snake could not get theoretically. So how to check such "unreachable" places on a level and not create incorrect walls?
PS: Sorry for my poor English.
Just do a google search for the "A*" Algorithm. The head of the snake is your starting point, the apples your end point and the walls your obstacles. (of course you would have to think about, how to get around the problem of interfering with your tail)

What kind of algorithm is well suited for optimizing seat allocation in opera house? [closed]

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 6 years ago.
Improve this question
So i have an opera houses with 10 rows and 10 columns of seats (Total :100). Each seat is allocated a preference value Aij. The preference value is halved if the group do not get seats in same row. Eg: If a reservation in opera house is for 5 people and only 2 can be accommodated in top row and 3 in next row, the preference value is actually halved for each seat. There are total of n reservations with 'n' > 100 seats. What will the best way to maximize the customer preference (n *Aij).If it can be done by linear programming, how should the equation look like.
I think this is not trivial to model as a MIP.
I gave it a try using a main binary variable x(i,j,g,r) where (i,j) is the row and column of the seat assigned to group g. The set r is {singlerow,multiplerows} to indicate whether the group is sitting in the same row.
Not sure if this is a particular good formulation, but it seems to work. Below are the equations I used:
I assumed that there are a number of groups g that each have a size. A group gets all seats it needs or it is not getting any seats.
I suspect that a constraint programming approach could be easier.
Conclusion: it can be done using a MIP formulation but it is somewhat cumbersome.

Pso based image enhacment [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to enhance my image by using pso based gray level image enhacment.I send the algorithm but i dont understand how I get particle of my image.pso paper
You only need to carefully read the section B. Proposed methodology. It says something like this:
Now our aim is to find the best set of values
for these four parameters which can produce the optimal result
and to perform this work PSO is used. P number of particles
are initialized, each with four parameters a, b, c, and k by the
random values within their range and corresponding random
velocities.
So there you have your particle generation. Each particle is a set of 4 random values.

Understanding the use of “before” in a programming task [closed]

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 working on task http://poj.org/problem?id=1884. I didn't understand just one part of it:
Adjacent stations on each route are far enough apart to allow a train to accelerate to its maximum velocity before beginning to decelerate.
Does it mean that train is accelerating and then going in constant speed/velocity before it goes to deaccelrate or it is accelerating for longer period, and when it comes to max velocity, it is immediately going to deaccelerate?
The fist one, yes, "train is accelerating and then going in constant speed/velocity before it goes to deaccelrate".
Basically the train accelerates as much as it can, then maintains maximum speed for the journey, then brakes as approaches the station.
What they meant was: if the station were too close, trains would have to accelerate then brake before reaching peak speed to be able to stop in the next station, but you don't have this problem.
from the text:
It remains at that maximum velocity until it begins to decelerate (at
the same constant rate) as it approaches the next station.

Cartesian plane spiral algorithm? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Consider touring the Cartesian plane spiral. The initial position is (0,0). in the first step you move to (1.0), in the second step (1.1), in step 3 you'll be in the position (0,1), step 4 takes you to (-1.1) and so on. In step 2012: At what coordinate are you arriving?, What will be the cordinate in 2121?
To find the nth coordinate ((0,0) is 0th), first take c=floor(sqrt(n)). If c*c==n, the coordinate is (c,c). Otherwise, if n-c*c<=2c, the coordinate is (c+c*c-n,c). Otherwise, if n-c*c<=4c, the coordinate is (-c,3c+c*c-n). Otherwise, if n-c*c<=6c, the coordinate is (n-c*c-5c,-c). Otherwise, the coordinate is (c,n-c*c-7c). Therefore, 2012 is (-29,44), and 2121 is (41,46). Please write the code yourself, this seems like homework.

Resources