SPOJ : BANKROB STATEMENT NOT CLEAR [closed] - c++

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
I have recently started practicing graph theory problems.
I recently encountered this problem : BANKROB
Even after having gone through the problem statement several times, I am unable to understand how the given output for the sample cases has been computed.
I will be grateful to you, if you can please explain the sample test cases.

I'll explain one.
The first line says the city has ten crossroads (nodes) and 14 roads (edges). This helps you set up the problem, but it's not really necessary because you can tell that from the remainder of the input.
The second line says the robbers' goal is to get from node 1 to node ten. (your goal is to stop them).
The third through 16th lines each represent one road (edge.) Note that there are 14 edges and ten nodes as predicted by line 1. This information lets you create a graph.
To capture the robbers you need block (delete) the fewest possible nodes to separate node one from node ten. As it turns out in this case deleting node five and six will do the trick, so the answer to the question is 2, the number of crossroads you need to delete.
Now how to compute this? Well that's what you are studying, right?

To understand the solutions, it helps to visualize the data that's depicted. (Of course, you'll have the computer program do this entirely differently.) Based on the input, the roads basically look like this:
2 - 5 - 7
/ / \ \
1 - 3 - 6 - 8 - 10
\ / \ /
4 9
To cut off all paths from 1-10, just remove the choke points at 5 and 6.
However, to cut off from 5-10 (assuming all the roads are bidirectional), you can't just remove 7 and 8 - the robbers can backtrack from 5-3-6-9-10. So you have to cut off 7, 8 and 9.
Thus, for the first example, there are 2 places to cut off, but in the second, there are 3.

Related

Whats the difference between the two approaches? [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 3 years ago.
Improve this question
I have this question in my assignment, and the solution states that we must have two pointing indices one at the start and one at the last element and we can progress from last element to the middle and respectively the first element to the middle. However, my solution was to have one index at the middle and another at last, and the last index will just move until the middle while the middle index will move until it reaches the start. But i am confused with what's wrong with my solution
Question:
Two stacks of positive integers are needed: one containing elements with values less than or equal to 1000 and the other containing elements with values larger than 1000. The total number of elements in the small-value stack and the large-value stack combined is never more than 500 at any time, but we cannot predict how many will be in each stack. (Initially both will be empty; later on the stacks could be evenly divided, or all the elements could be in the small-value stack, and so on.) For efficiency reasons, we want to implement both stacks using a single array of size 500. Can you think of a way to do this
Take the number 10 (less than 1000) and 400 numbers from 2001 to 2400 (greater than 1000) and try to put them on the two stacks. You will see that the solution with pointers on the two ends will work. But the solution with one pointer in the middle will not work, one of the stacks will be too small or the small value will be overwritten.

Detect extreme value vector C++ [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 4 years ago.
Improve this question
I have a vector of values (delays) like this {2,4,6,3,4,5,6,4,..} in C++. My objective is to detect when a new value is an extreme value - for example, 96. I am trying to come up with a general check to detect instead of putting specific numerical checks.
By extreme value I mean 96 would be X times larger than 2 or 3 or 4. However, if I have delays as {15,23,10,26,..} and then a value 550, which is Y times larger than normal - I want to detect.
I need to start with the standard deviation, but not sure about the best approach further.
Thank you.
In the absence of any other statistical information, compute the mean and the standard deviation of the mean of your existing data, and if the new point is more than 3 standard deviations of the mean outside that mean, then don't add it.
After you have a certain number of points so you can be reasonably sure that the central limit theorem has started to work its magic (20 points as a rule of thumb, especially as "delays" implies "Poisson" on first glance), develop an algorithm to eliminate any outliers that might have been added to the initial set. Do that by considering each added point in turn - eliminate it, and see it matches the criteria for inclusion. This step is important: it's designed to fail an outlier that's introduced early; e.g. {2, 96, 4, 6, 3, 4, 5}. For really hostile data you might need to increase the dimensionality of that algorithm.
This is a tricky science - you'll have to calibrate this to suit your requirements but what I suggest will get you started.

Calculation with operators [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
I know this looks like homework, but it isn't.
Please develop a program which could take in 5 ints (from 1 to 9), and use +, -, *, /, (, ) these operators to calculate at least one equation to make the result = 24. The operators, you do not need to use all of them, and also, you could use each of them as many times as you want.
For example, if user put in 3, 8, 1, 1, 1 to your program, the result should be:
3 * 8 / 1 / 1 / 1 = 24
I don't want the actual solution to this, but could someone please give me some starting tips?
could someone please give me some starting tips?
Tip #1:Get started. It doesn't matter that you don't know how to write this program, just write the simplest program you can to get started and then build from there. You can write Hello World, right? Do that. Do you know how to accept input from the user? Add that. Building a program that can accept input and print output will get you significantly further than you are now.
Tip #2: Break it down. Instead of worrying about how to accept five integers and operators, can you do two? Or maybe just accept two integers and print their sum to start. Once you're that far, you'll have a much better sense of what you'd need to do to accept operators and more numbers.
Tip #3: Ask for help (at the right time). Right now, you don't have anything done at all, so everything seems overwhelming. You can't even sort out what you know from what you don't know, so you don't know enough to ask a good question. Once you get started, you'll start to home in on the things you really don't know. Those things will be much better defined at that point, and you'll be able to do a more focussed search for solutions. Chances are, someone has already asked questions about the same things you don't understand, and you'll be able to find those questions once you know what to focus on. If not, you'll be able to ask a much more specific question that provides enough details to let someone help you. Those are exactly the kinds of questions that tend to get up votes and good answers, and (more importantly) really help you learn something.
Tip #4: Forget the computer. Try solving the problem with index cards, where each card represents some piece of data, like a number or an operator. Sometimes this helps you see how the data should be organized in order to solve the problem. Solving a problem in the real world helps you develop a mental model for solving it in code.

C++ Algorithm Prediction, need to predict 3 numbers [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
let's go straight to the facts.
I am studying for my own interest an eventual prediction algorithm for some unexistent lottery.
Let's say they roll out 3 numbers every day.
And those numbers are in range from 0 to 50.
I am asking, what would be the best approach to try to predict next 3 numbers knowing
all previous historic ones?
1. What i have
I have a list of 3 numbers from a range of {0,50} (integers)
<x0,y0,z0>
<x1,y1,z1>
<x2,y2,z2>
<x3,y3,z3>
Those numbers represent winning values of lottery.
2. What i need
I need to predict next 3 lottery numbers(possible WINNERS) by taking previous numbers into consideration
The order of the predicted numbers doesn't mater. It might be 1,2,3 or 3,2,1.
3. Question
Which approach / algorithm should i choose and why?
Super thanks for any help!
If the numbers you roll out are random, there is no way to make a prediction, as the next numbers are not linked in any way to the previous one. The most you can do is a guessing algorithm.

Generate prime factors of a number [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
I'm trying to write a function that given an Int greater than one gives a non decreasing list made of the prime factors (with repetition) of that number
Example: n = 12, the output should be [2,2,3]
I don't know where to start.
There are of course well know algorithms for what you want to do, so simple google search would really solve that.
However, I'd like to show you a simple thinking process that might be helpful in the future.
Since the factors have to appear in the ascending order, you might:
Start with the lowest prime (2).
Check if the number can be divided by it. If it can, do it and go back to 1.
If not, replace 2 with a next prime and go back to 2.
Now, it's obvious that the biggest prime you will ever check is the number you've started with. However, the basic multiplication axiom states that if a number can be divided by a:
n / a = b
Then it can also be divided by b! You can use that fact to further narrow the checking range, but I'll leave it to you to figure (or google) the upper bound.
Actual implementation is of course a part of your homework and thus supplying code wouldn't be a wise idea here. However, I don't think that stuff such as next_prime will be hard for you.