glory for dreams
BAN USER- 1of 1 vote
AnswerSkynet
- glory for dreams in United States
Skynet has grown to become the dominant force on earth and has almost completely wiped out the
human race. Skynet has been
building robots ever since it's inception and has been updating it's models every year while making
them better. Skynet wants to annihilate humanity completely. It plans to remove one last band of
humans lead by John Connor. Skynet thinks it can destroy these humans using only two of it's robots.
But Skynet doesn't want to send two robots with the same model number lest John Connor finds out a
weakness in that model and easily destroy both of them.
Skynet has at its disposal N robots and to save space Skynet has stored information about pairs of
robots belonging to the same model. If it doesn't have any info stored for a particular robot then it is
implied that the robot is the only one in that model.
Given these constraints, in how many ways can Skynet pick two robots to destroy John Connor and
his rag tag group of humans.
Inputs
N Total
number of robots. Each robot is assigned a number from 0 to N1
(2 <= N <= 100000)
P Number
of pairs for which Skynet has information (2 <= P <= 100000)
This is followed by P pairs. Each pair has two numbers P and P each where 0<=P <=N1
and
0<=P <=N1
and P != P
Output
Number of ways in which Skynet can select 2 robots such that both the robots are different models.
Example Input:
4 2
0 1
2 3
Example Output:
4
Explanation:
Here robots 0 and 1 are of one model, say model A. And 2 and 3 are of another model, say B.
Therefore the total number of
possibilities of picking 2 robots such that no two robots are of the same model are (
0, 2), (0, 3), (1, 2)
and (1, 4) = 4| Report Duplicate | Flag | PURGE
National Instruments SDE1 C++ - 0of 0 votes
AnswersGLaDOS is feeling bored, so she decided to come up with a board game. The game is as follows. There is
- glory for dreams in India
board of dimension n x n (2 <= n <= 10). Each position in this board is either a 0 or a power of 2, between 2
and 2048. Once the board is set up, there are only two moves allowed - move all left or move all right.
The way move all left works is as follows:
For every row on the board, starting from the rightmost position each element is moved to its left. An
element with a zero value does not move. An element with non-zero value can move to its left if the value of
the element to its left is a 0 or has the same value as the current element.
In case, the element to the left is 0 then the element and 0 swap positions i.e., 4 0 0 4 would become 4 0 4 0
In case, the element to the left has the same value as the current element then the left element combines
with its right element and creates an element with double the value in place of the right element and leaves
a 0 in its current place. For e.g., 2 2 would become 4 0 or 2 2 2 2 would become 4 0 4 0.
The combining operation can cause a cascading operation i.e., if the new element created has the same
value as the element to its left, it can combine again.
For e.g., if a row had 8 4 2 2, move left would combine 2 and 2 to form 4 leading to 8 4 4 0. Now, it is
possible to combine further as the element to the left of 4 has the same value, thus after the second
combine, the row would be 8 8 0 0. And again 8 and 8 would form a 16. Thus the final values in the row
would be 16 0 0 0.
But if the row was 8 4 2 0 2, then moving left would result in 8 4 2 2 0. The cascading operation is allowed
only after a combination operation, There would no cascading operation if the element is swapped with 0.
Similar rules apply for move all right, wherein for every row elements starting from the leftmost position
move to their right.
You can either choose move all left or move all right operation but not both. Now given a state of the board,
you have determine what will be the maximum value on the board after either move all left or move all right.
Example
3
2 2 0
2 2 4
2 0 2
Move all left would result in:
4 0 0
4 0 4
2 2 0
The maximum value on the board after this move is 4.
Move all right would result in:
0 4 0
0 0 8
0 2 2
In the first row, 2 and 2 combines to form 4. In the second row, left most 2 combines with 2 to form 4. As the
element to its right has a value 4, combination operation cascades to form 8.
The maximum value on the board after this move is 8.
Now of the two operations, the higher of the two maximum values is 8. Thus the expected output is 8.
Input
3
2 2 0
2 2 4
2 0 2
Output
8
Input
3
0 0 4
0 2 2
0 4 8
Output
8
Time limit per test case:
1 second(s)| Report Duplicate | Flag | PURGE
National Instruments Software Developer C C++