Вы находитесь на странице: 1из 53

IEEEXtreme Programming Competition 7.

0
1. Lenovo Problem

Lenovo is working hard to help scientists in biology especially in Bioinformatics to build
computers that can handle big biological computations and handling huge set of information. In
this problem you will need to help solve one of those tasks.

In Bioinformatics, the term Sequence Alignment is used to describe the task of arranging two
or more biological sequences (DNA, RNA or Protein) in such a way that regions of similarity
between the sequences can be easily identified and thus conclusions about the evolutionary
relationships between them may be inferred. In order to make the conserved regions more
apparent, usually each sequence is represented in a distinct row within a matrix, whereas gaps
are also inserted between the sequences residues so that identical or similar characters are
aligned in successive columns [Source: Wikipedia: Sequence alignment]. An example of one
possible alignment for the sequences Seq1 = ACGCATTCG, Seq2 = ACGAGTGG, Seq3 =
CGATTAG is presented at Table 1:

Table 1. One possible alignment for the Sequences: Seq1 = ACGCATTCG, Seq2 =
ACGAGTGG, Seq3 = CGATTAG (Gaps are denoted by a dash -)


This alignment indicates that the first residue (A) of Seq 1 is alignment to the first residue (A) of
Seq 2 and to nothing (gap denoted by a dash) to Seq 3. In a similar way, from the second
column of the alignment it is made clear that the second residue of Seq 1 (C) is aligned to the
second residue (C) of Seq 2 and to the first residue (C) of Seq 3.

Obviously, this is only one possible alignment for the aforementioned sequences and many
more arrangements are possible. Could you help me create a program that can efficiently
generate all possible unique (gapped) alignments for a given set of sequences?

Task
Your task is to develop a program that can efficiently generate all the possible unique
alignments for a given set of sequences.

To better understand the task of the present problem, please consider the following two
examples:

Example 1:
if the input sequences were: Seq 1 = AC and Seq 2 = GG, then the following 13 unique
alignments are possible:

Example 2: if the input sequences were: Seq 1 = ACT and Seq 2 = GC, then the following 25
unique alignments are possible:

Since the number of possible alignments grows exponentially by the number of the sequences
to be aligned and the number of residues forming each sequence, you can safely assume that
only toy examples (i.e. only a few sequences comprised of a limited number of residues) will
be considered.

As it may be inferred by the examples above: All the sequences in each alignment have
the same length (number of columns) and whenever it is required gaps are inserted between
the sequences residues If no gaps need to be inserted then they are skipped (like for
example in the alignment 1 of Example 1). In other words, columns containing only gaps are
considered irrelevant to the alignment task and should not be printed. In every alignment
the order of the sequences is kept (e.g. in the examples above, always Seq 1 is in the first line
of the output followed by Seq 2) Also, the order of the residues forming each sequence is
always respected (i.e. if the sequence is ACT then always the A appears first then the C and
finally the T) Regarding the order of the alignments in the final result set, the following rules
have to be respected: The alignments should be sorted in increasing order according to
the length (number of columns) of the alignment If two or more sequences have the same
length, then these alignments should be sorted in alphabetical order according to the sequences
in the alignment: Initially, the first sequence of the alignments will be used to decide on the
order of the sequences If there still exist two or more alignments that have exactly the
same length and also are identical in terms of the first sequence, then the alphabetical order of
the second sequence of the alignments will be used to decide the ranking of these alignments.
If there are still two or more alignments that have exactly the same length and also are
identical in terms of the first and second sequence, the algorithm will continue likewise using the
third, fourth etc sequence of these alignments. Please also refer to the provided examples
where the alignments are listed in the proper order according to the above sorting rules. For
instance, in Example 1, Alignment 1 is positioned first in the list of results since its length (2) is
smaller than the length of any other alignment in the result set. Also, in compliance with the
ordering rules, Alignment 2 of Example 1 is ordered before Alignment 4 since the first sequence
of Alignment 2 (AC-) precedes alphabetically the corresponding first sequence of Alignment 4
(A-C). Moreover, the ordering between Alignment 2 and Alignment 3 (which both have length
equal to 3 and sequence AC- as the first sequence) is decided by the alphabetical order of the
second sequence in these alignments, where the second sequence of the Alignment 2 (G-G)
precedes alphabetically the corresponding second sequence of Alignment 3 (-GG). In order to
avoid issues from printing huge result sets, instead of outputting all the possible alignments for a
given set of sequences, your program should output only the total number of possible
alignments as well as the alignments at some predefined positions that would be given as input
to the program.

Input:
Your program will receive the following input and in the following order from the Standard Input
Stream: N: This number will always be a positive integer value smaller than 6
representing the number of sequences to be aligned Then N lines will follow representing
each one of the sequences to be aligned. Each sequence will be comprised of M residues
belonging to the alphabet A={A, C, G, T} A positive integer value K will follow representing
the number of alignments that would have to be outputted to the screen Then K lines will
follow each one containing an integer value representing a position in the ordered list of
alignments that should be printed on the standard output stream (Note: You should consider
these positions to be 1-based meaning that if for example the position equals to 4, then the 4th
alignment in the ordered list should be printed).

Output:
Your program should output to the Standard Output Stream the total number of possible
alignments for the given set of sequences as well as the alignments (as contained in the
ordered result set) at the positions specified from the given input. In particular, the output should
be formatted as follows: The first line of the output should always be: Possible Alignments:
e.g. Possible Alignments: 25 Note: There is a space between the colon and the number Then K
sets of lines should follow each one printing the alignment at the specified position of the
ordered list of results. The format for the alignments should be as follows: If no
alignment exists at the given position then the following line should be printed: There is no
alignment at position: e.g. There is no alignment at position: 1000 Note: There is a space
between the colon and the position If there exists an alignment at the given position, then at
first the following line should be printed: Alignment at Position: e.g. Alignment at Position: 15
Note: There is a space between the colon and the position And then the alignment at this
position of the ordered list should printed with the sequences ordered as they were given in the
input. If for example the input sequences were Seq 1 = ACT and Seq 2 = GC (as in Example 2),
and the given position was 15, the program should print: -ACT G--C Note: Each sequence ends
with a newline character and does not contain any spaces before or after the sequence
Sample Input 1
2
AC
GG
6
-9
1
13
5
100
8

Sample Output 1
Possible Alignments: 13
There is no alignment at position: -9
Alignment at Position: 1
AC
GG
Alignment at Position: 13
--AC
GG--
Alignment at Position: 5
A-C
-GG
There is no alignment at position: 100
Alignment at Position: 8
AC--
--GG

Sample Input 2
2
ACT
GC
5
1
9
22
14
32

Sample Output 2
Possible Alignments: 25
Alignment at Position: 1
ACT
GC-
Alignment at Position: 9
AC-T
--GC
Alignment at Position: 22
-ACT-
G---C
Alignment at Position: 14
-ACT
G-C-
There is no alignment at position: 32

2. Acadox Problem
Acadox vision is to provide innovative and modern Learning Management technologies that
empowers the faculty and students to engage and collaborate in a simple and efficient manner.

One of the professor, who loves Acadox so much, posted on his page as a teaser problem for
his students to prepare for their programming exam. The problem posted was as follows:

Develop program that emulates a simple hexadecimal calculator that uses postfix notation.
Perform the operations of addition, subtraction, logical and, logical or, logical not, and logical
exclusive or.


Description
Since Acadox is social environment for learning. The professor posted the following description
on his page: The programmers calculator accepts a string of hexadecimal digits and operators
in reverse Polish (postfix) notation then produces the result. Input digits represent 16 bit
unsigned binary bit strings.

Input
The program must accept a sequence of operators and hexadecimal digits following the postfix
form, as follows.

Digits: Leading zeros are optional, alphas are not case sensitive: {[0-9 | A-F | a-f]}1-4

Operators :


Each input item is delimited by a white space. An input stream is terminated with a new-line. No
more than 20 items are accepted.
Output
The program must display the result of evaluating the entire postfix expression as single
hexadecimal string, with leading zeros and upper case letters. If any input is invalid, the string
ERROR is displayed.

All operations are bitwise there is no representation of negative quantities. An overflow: x + y
> FFFF results in FFFF. An underflow, x y < 0000, results in 0000.

Sample Input 1:
1 1 +

Sample Output 1:
0002


Sample Input 2:
F 1 -

Sample Output 2:
000E


Sample Input 3:
F - 1

Sample Output 3:
ERROR


3. IEEE Computer Society Problem
IEEE Computer Society was working on a little secret project in one of their labs around the
world to build a little Robbie with human sense and lots of intelligence. While being in the lab all
the time, the little Robbie decided to break himself out and search for a new adventure. While
the little Robbie was looking for new adventure he decided to enter an ancient Incas maze
located nearby. As little Robbie is too young, he has not yet learned any sophisticated ways to
get out of the maze, but fortunately he was taught at school that the right-hand wall follower
algorithm is always guaranteed to lead to an exit in the case of a simply connected maze.
Nevertheless, this maze is a dynamic one and every time Robbie makes a move, the maze
topology changes. Would Robbie be able to finally get out of the maze?
Task
Your task is to develop a program that can efficiently simulate the scenario of little Robbie being
trapped in a dynamic maze.
a) The Linear Congruential Generator
Since randomness will be necessary for this problem, your first subtask includes the
development of a custom pseudorandom number generator that will be used in all cases where
a random number has to be drawn.
A Linear Congruential Generator (LCG) represents one of the oldest and best-known
pseudorandom number generator algorithms.
The generator is defined by the recurrence relation:
X(
n+1
) = (a * X
n
+ c)mod m
where:
X is the sequence of pseudorandom values,
m is the modulus, m > 0
a is the multiplier 0 < a < m
c is the increment 0 < c < m
X
0
is the seed or start value 0 < X
0
m
source:wiki
For the case of our LCG, we will assume the X, m, a, c and X
0
values will be of integer type.
Also we will always use
m = 2
32

a = 1664525
c = 1013904223
and only the start seed value will change (will be an input parameter provided from the standard
input stream).
Whenever a random positive integer value within a specific range [min, max] is required, then
such a value may generated using the absolute value of our custom LCG and the modulus
operator. For example, if we want to draw a random integer in the range [1, 100] (i.e. between 1
and 100 inclusive) then the following formula can be used:
rand
num
= abs(X(
n+1
)mod 100+1)
For example, the first 15 randomly generated values for
X
0
= 999
m = 2
32

a = 1664525
c = 1013904223
alongside with their corresponding [1,100] mapping are presented at Table 1.

b) The Maze
The maze is composed of M rows and N columns (M and N being positive integer values) and
consequently of M*N cells. Such an exemplary 10x10 maze is graphically depicted at Figure 1.
Regarding the maze, please also consider the following definitions as they will be used
throughout the problem description:
Corner Cells: The four cells located at the corners of the maze (highlighted in gray at
Figure 1). These cells always accommodate the four pillars of the maze and are
inaccessible to the robot. Also they cannot be used as start or exit positions.
Border Cells: The cells positioned at the four edges of the maze - excluding the Corner
cells (highlighted in red at Figure 1). These are the only cells that can be used as start
and exit positions.
Inner Cells: All the remaining cells of the maze - excluding the corner and border cells
(highlighted in yellow at Figure 1). These cells cannot be used as start or exit positions,
but may be accessible by the robot.
Start Position: The position where the robot starts when it first enters the maze. This cell
can be any of the Border cells.
Maze Exit: The cell leading to the exit of the maze. This can be any of the Border cells,
but it must be different to the start position (i.e. the exit and the start position cannot be
located on the same Border cell)
Each one of the maze cells may or may not have a wall on each one of the 4 directions: North,
South, East, and West (please refer to the compass at Figure 1). Walls (and equivalently
openings) that are shared by adjacent cells will be accounted for both cells respectively. For
example the East side wall of the rightmost cell in Figure 2b, should also be considered as a
West side wall for the middle cell. Equivalently, the East opening of the middle cell should also
be considered as an opening for the West side of the leftmost cell. The decision about whether
a specific cell will have a wall on each one of the four possible directions will be based on a
given positive integer Probability value
1 <= P
wall
<= 100
that will be received as input to the program from the standard input stream.

Figure 1. Graphical Depiction of a random maze topology. The pillars are located at the four
corners of the maze and are highlighted in gray. The Border cells are highlighted in red and the
start and exit positions are also depicted. The yellow highlighting signifies the inner cells of the
maze.

Figure 2. (a) A maze cell having a border on all 4 directions: North, South, East, and West. (b)
Three adjacent maze cells. The first cell (on the left) has a North and West wall, the second cell
(in the middle) has a North, South and East wall and the third cell (on the right) has walls on all
4 directions.
Also, please take in account the following Ordering Rules:
1. Ordering Rule 1: Whenever a full traversal of the maze is required, it should always be
performed by row (meaning that starting from the first row of the maze, at first all the
columns of the current row should be visited and then the program should proceed to
parse all the columns of the subsequent row).
2. Ordering Rule 2: Whenever a full traversal of the four possible directions is required, it
should always be performed according to this order: a) North, b) South, c) West and d)
East.
Regarding the construction of the maze, the following steps should be followed in the specified
order:
1. An M x N maze should be constructed based on the given M and N values.
2. For the starting maze topology, all maze cells (i.e. Corner, Border and Inner Cells)
should be considered to have walls on all four directions (North, South, East, and West).
3. Then, one Border Cell should be selected at random as the Start Position of the maze.
This should be done by drawing a random number from the custom Linear Congruential
Generator between [1, n], where n is the total number of Border Cells. The order of the
Border Cells should be as described by the Ordering Rule 1 (i.e. at first all the Border
Cells of the 1st row should be considered, then the ones at the 2nd row and so forth).
4. Afterwards, another Border Cell (different to the Start Position) should be selected at
random as the Maze Exit. This should be done by drawing a random number from the
custom Linear Congruential Generator between [1, k], where k is the total number of
Border Cells, after having removed the Border Cell that is used for Start Position from
the set of Border Cells. Then,
a. If the Maze Exit is located at the Northern Edge of the Maze, then it should have a North Side
opening.
b. If the Maze Exit is located at the Southern Edge of the Maze, then it should have a South
Side opening.
c. If the Maze Exit is located at the Eastern Edge of the Maze, then it should have an East Side
opening.
d. If the Maze Exit is located at the Western Edge of the Maze, then it should have a West Side
opening.
1. Finally, for each one of the Inner Cells (again the inner cells should be traversed by row
as described at the Ordering Rule 1):
2. a. A random number between [1,4] should be drawn using the custom Linear
Congruential Generator:
If this random values equals to 1, then this Inner Cell should have an opening at the
Northern Side and equivalently the cell positioned northern to this cell should have an
opening at its Southern side.
If this random values equals to 2, then this Inner Cell should have an opening at the
Southern Side and equivalently the cell positioned southern to this cell should have an
opening at its Northern side.
If this random values equals to 3, then this Inner Cell should have an opening at the
Western Side and equivalently the cell positioned western to this cell should have an
opening at its Eastern side.
If this random values equals to 4, then this Inner Cell should have an opening at the
Eastern Side and equivalently the cell positioned eastern to this cell should have an
opening at its Western side.

Figure 3 shows the starting maze topology when using
X
0
= 999
m = 2
32

a = 1664525
c = 1013904223
as initial values for the custom Linear Congruential Generator and following the above steps.
c) The Robot
The robot can only look at one direction at a time (North, South, West or East) and it can only
perform one of the following two moves:
a. Step: If there is no wall at the direction the robot is currently looking at, and also there is a
wall to the right of the robot then it can move one step towards the direction it is looking at (i.e. it
may progress to the next cell)
b. Turn: If there is a wall at the direction the robot is looking at, or there is no wall to its right then
the robot should make a turn. The turn should always be performed in a clockwise direction.
When the robot enters the maze for the first time it should always look towards the east. Then it
should start traversing the maze trying to find the exit simply by following the right-hand wall
follower algorithm, meaning that it should keep its right hand in contact with the wall located to
its right
see also Maze Solving Algorithm for more details on the wall follower algorithm
Every time the robot makes a move (either a step or a turn), the Inner Cells of the maze should
be dynamically updated as follows:
1. For each Inner Cell (traversed according to the Ordering Rule 1) each one of the 4
directions (ordered as North, South, West and East see Ordering Rule 2) should be re-
examined. In particular:
a. A random number between [1, 100] should be drawn from the LCG and if this random value
is smaller to a given (as input to the program) integer Probability value 1 <= P
wall
<= 100 then
this innerl cell should ahve a wall at this direction. If the random value is larger or equal to P
wall

a. then this Inner Cell should have an opening at this direction. Every time a wall appears or
disappears at a specific cell, the corresponding state of its adjacent cells should also be
updated (for example, if a cell gets to have a wall on the North Side, then the cell positioned
northern to this cell should also be updated to have a wall at its Southern side).
Note: During this maze update step, it might happen that a cell (when traversed in its order) may
not to have a wall on one directions (e.g. its South Side), but it finally gets to have a wall at that
direction because of an adjacent cell of it. For example, it might happen that a cell (A) was
decided not to have a wall at its Southern Side when this cell was traversed, but it finally ended
up with a Southern Side wall because another Cell (B) positioned to the South of Cell (A) was
later on traversed and was randomly assigned a wall to its Northern Side.
Figure 4, shows the robot and maze topologies for a set of 12 robot moves (steps or turns)
according to the aforementioned guidelines using
X
0
= 999
m = 2
32

a = 1664525
c = 1013904223
as initial values for the custom Linear Congruential Generator.


Since the robot fuel is not endless, the robot can only perform a limited number of moves (steps
or turns) before it runs out of fuel. The number of moves that the robot can make before it runs
out of fuel will be given to the program as input from the standard input stream. The program
should terminate when the robot reaches the maze exit or when the maximum number of moves
has been reached.
Input for the LCG, you should always use the following starting values:
m = 2
32

a = 1664525
c = 1013904223

Also, your program will receive the following input (one parameter per line) in the following order
from the Standard Input Stream:
1. Seed: A positive integer value used as initial seed (start value X0) for the LCG.
2. M: A positive integer value representing the number of rows of the maze.
3. N: A positive integer value representing the number of columns of the maze.
4. 1 < P
wall
< 100 : A positive integer value representing the probability of having a wall on
each one of the four possible directions (North, South, West, East).
5. Moves: A positive integer value representing the number of moves that the robot can
make before running out of fuel.
Output
If Robbie manages to find the Maze Exit before it runs out of fuel the following message
should be printed to the Standard Output Stream:
Robbie got out of the maze in moves.
e.g. Robbie got out of the maze in 2798 moves.
If Robbie runs out of fuel before managing to find the exit, then the following message
should be printed to the Standard Output Stream:
Robbie was trapped in the maze.
Note: Each sentence ends with a dot followed by newline character.

Sample Input 1
999
10
10
50
1000

Sample Output 1
Robbie got out of the maze in 179 moves.


Sample Input 2
1100
20
30
50
3000

Sample Output 2
Robbie got out of the maze in 1962 moves.




IEEE Women In Engineering Problem
IEEE Women In Engineering mission is to facilitate the global recruitment and retention of
women in technical disciplines. To do that, they decided to release a problem for public
audience to optimize city train system as a gesture that everyone can be an Engineer. The
problem as follows:

For m trains and single track with n stations, compute station arrival and departure times so that
only zero or one train is between any pair of stations at any time and inter-station travel time is
minimized. Given: acceleration rate, maximum speed, deceleration rate, minimum time stopped
at a station and lengths of track, sections, trains, and stations.


Description
Trains leave a depot and arrive at a terminal, running over a single track. The track is 100
kilometers long. A track may have from 0 to 10 stations. The track between two stations is
called a section and is at least 500 meters. Each station parallels 150 meters of track. Figure 1
shows these relationships.


A train is 100 meters long. All trains accelerate at constant rate of 2.7 kilometers per hour per
second, cruise at a top speed of 90 kilometers per hour, and decelerate at a constant rate of 3.8
kilometers per hour per second. Trains must accelerate, cruise, and decelerate so that they to
come to a complete stop at the next station while minimizing the time to travel a section.

Recall that d=(a*t^2)/2, where distance traveled d is a function of acceleration (or deceleration)
a over period t, assuming an initial velocity of 0. In short sections, the train will not reach its
cruising speedit will simply accelerate then decelerate. For a sufficiently long section, the train
accelerates to cruising speed, cruises, and then decelerates to stop at the station.
A train must stop at a station for at least two minutes after it arrives. Trains stop at the far edge
of the station. A train is considered to have arrived at the Terminal when the first car reaches
the Terminal. To ensure safety, only one train may be in any section at time. If train is ready to
depart, it must wait until the next station is empty. A train may depart one second after the next
station becomes empty. The last section is considered clear when a train arrives at the
Terminal.

Task
For a given set of sections up to five trains, write a program that computes the arrival and
departure time for each train at each station, achieving all of the stated operating conditions.

Input
The program must accept input in the form N {d} 0..m, for N trains, section distance dm, or ,
<section 1 distance >, < section 2 distance>,, < section m distance >

All inputs are unsigned integers, separated with a space. All distances are in meters
- Accept from 1 to 5 trains - Accept from 1 to 5 sections - The total of the sections must equal
100000

Output Data
If the input format is invalid or conflicts with the problem specification, the program must output
only ERROR The schedule is of the form {n:{ta-td}}

Where n is the train number followed by a colon, ta is the arrival time at the mth station and td is
the departure time at station m+1. Arrival-departure times are separated with a dash.

Schedule times for the Depot and Terminal are special cases: the arrival and departure times
are the same. The first train departs the Depot at time 1. All output values are unsigned
integers. Times are in seconds, rounded to the nearest whole second.

The output format must follow the below format. The tilde indicates a single space. Assuming
one train T, and two sections, the output would be:
T~: *****~-~ddddd~~aaaaa~-~ddddd~~aaaaa~*****


Where ddddd is the departure time, aaaaa is the arrival time. Both are five digits with leading
zeros suppressed. The asterisks indicate an unspecified arrival or departure time. See following
examples.

Sample Input1:
3 400 400 99000

Sample Output1:
ERROR



Sample Input2:
0 50000 50000

Sample Output2:
ERROR



Sample Input3:
2 60000 60000

Sample Output3:
ERROR



Sample Input4:
12 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000

Sample Output 4:
ERROR



Sample Input5:
2 5000 50000

Sample Output 5:
ERROR



Sample Input6:
Fja 3 nasdfpij NASD;ASD

Sample Output 6:
ERROR



Sample Input 7 (One train, one section):
1 100000

Sample Output 7:
1 : ***** - 1 4030 *****



Sample Input 8 (Two trains, three sections)
2 500 500 99000

Sample Output 8:
1 : ***** - 1 49 - 170 218 - 339 4328 *****
2 : ***** - 171 219 - 340 388 - 4329 8318 *****



Problem_AR
There is an entertainment park visited by thousands of people every day. The intention of every
visitor is to view most of the entertainment events/shows available in the park. The Manager of
the entertainment park also wants that visitor of the park should view most of the shows, which
will bring more publicity and profit to the company. For doing this the manager of the park plans
to schedule the shows in such a way that there is the least overlapping between the shows.

In addition to this there are some Signature events/shows of that entertainment park. As per the
company policy, no one should miss these events and these events should be given priority
when scheduling the shows.


Task
Your task is to write a program that will be able to reduce the overlapping time while also giving
more priority to the Signature events of the entertainment park.

Input
The input of the program will always be two lines provided through the standard input stream.

The first line will begin with a positive integer number N (1<=N<=10) representing the total
number of shows available in the entertainment park. Then N integer values will follow
(separated by a space) representing the length of each of the N shows.

The second line of the input refers to the key break points that correspond to the Signature
events/shows. It starts by a positive integer number M (1<=M<=4) reflecting the total number of
key break points (one key break point for one signature event) followed by M pairs of integer
values (each pair separated to another by a space). Each pair is comprised of two space-
separated positive integer values, the first one representing the time after which the important
show will be starting (i.e. time interval between which other shoes of the park may take place),
whereas the second integer value reflects the importance level of this show. Importance level 1
is higher than 2 and levels are limited up to level 4.

For example, the following input:
4 40 60 50 30
2 60 1 60 2


Implies that there are 4 (normal) shows on that day with durations 40, 60, 50 and 30 minutes
respectively. Also, in the second line it is stated that there exist 2 key break points:

the first one having a significance level equal to 1 (utmost importance) and before this event
comes up, other shows of total duration summing up to nearly 60 minutes may take place

the second one has a significance level equal to 2, and before this event comes up, other shows
of total duration summing up to nearly 60 minutes may take place

Output
Your program should output to the standard output stream the sequence in which the shows
should be planned so that all visitors attend all the Signature events/shows minimizing at the
same time the overlap between the rest of the shows. Shows of same length may be in any
order, provided that it does not alter any of our objectives and the solution remains as optimal.
Your program should also display the minimum overlap between the shows. Overlap means the
time period which the visitors will miss in viewing the shows by following this schedule. The time
period missed with respect to important shows cannot be more than minimum duration of the
less important shows.

For example, for the expected output for the input provided above would be:
60 40 30 50
Overlap 10 of Level 2


Which implies that at first the (less important) show having a duration of 60 minutes should be
viewed, allowing then for the Signature event with importance level 1 to take place, then the
(less important) shows with duration 40 and 30 minutes should come up, followed by the second
Signature event with importance level 2 and finally the last (less important) show with duration
50 minutes should come up. Since before the signature event with importance level 2 the total
duration of the shows is (40+30=70 minutes) this by definition implies that all visitors will have a
10 minutes overlap between these two shows in order to fully attend the signature event with
importance level 2.

Consequently, the output displays this overlap (Overlap 10 of Level 2).If there is no overlap,
then the program should output the line Overlap Zero instead. In cases of equivalently optimal
solutions, the shows contained in between the significant events, should always be listed in First
fit order of the input of the show timings.

Note: There is a newline character at the end of the last line of the output.

Sample Input 1:
5 30 15 45 45 15
3 60 1 80 2 15 3

Sample Output 1:
15 45 30 45 15
Overlap 5 of Level 2



Sample Input 2:
4 40 60 50 30
2 60 1 70 2

Sample Output 2:
60 30 40 50
Overlap Zero



Sample Input 3:
5 30 30 40 60 25
1 90 1

Sample Output 3:
30 60 25 30 40
Overlap Zero
Problem_AS

People in the city of Herat hold the record of maximum number of Ice cream consumption on
any day of the year. There is a popular Brand called Ice-Xtreme which supplies most of the Ice
cream in the city. The company takes the help of the City Maps and the Traffic Department to
supply the product to various vendors in the city as per their requirement. Nevertheless, every
day few of the roads are closed for better traffic management or due to repair work etc. Daily
Bulletins are available for checking the availability of open roads.

The City has a very good architecture and it is divided into non-overlapping areas called blocks.
Blocks are of arbitrary shapes. The Distribution is done through a Warehouse in every such
block. Whenever the manager of the warehouse gets a phone call for delivery of the Ice Cream,
he sends out his van to fulfil the order. Your program should output the shortest route (Which
touches minimum number of turnings) from the Warehouse to the ice cream vendor. Obviously,
it should not include any of the roads which are not usable on that day.

Source: Microsoft Clipart)

Task
Each block in the city may have a different layout. All the road turnings in each block are
identified by a single alphabet letter ranging between F to Z. There is no specific order or rule
about the way the road turnings are named with the alphabet.
In each block the warehouse is always at F.
Your task is to write a program that outputs every possible route for the van to supply the Ice
Cream to the vendor, the total number of possible routes and the optimal route that should be
taken according to the provided open roads and vendor location.

Input
The program should receive the input from the standard input stream. The first line of the input
will be an alphabet letter (between F and Z) representing the road corner that is located nearest
to the vendor who has requested the ice cream supplies.

Then N lines will follow comprised of pair of alphabet letters (between F and Z) separated by a
space representing the roads that are currently open and thus may be used by the van to
deliver the supplies. For example the pair L P shows that the road between Road Corner L and
Road Corner P is open and there is no other corner between L and P. Likewise, there can be
many such pairs (each in its own line) for all open roads that may be followed. The input will end
with the pair A A.
Output
The output should report to the standard output stream the total number of possible routes.
Apparently, the reported tours should not contain the same road visited twice which will mean
a cycle. The last line of the output it should print the shortest route. In case there are more than
one as equally as optimal routes, the tie should be resolved by printing the route which if
considered as a string, comes first in the (incremental - from A to Z) alphabetical order. If you
think there is no such route available on that day due to closure of many roads then you should
print No Route Available from F to {the vendor}.

Note 1: There is a newline character at the end of the last line of the output.

Note 2: There is a space character after the : character of the output lines.

Sample Input 1:
K
F G
F H
H I
H J
I K
J K
G H
G I
A A

Sample Output 1:
Total Routes: 7
Shortest Route Length: 4
Shortest Route after Sorting of Routes of length 4: F G I K



Sample Input 2:
Z
F M
S T
U V
W X
Y Z
J K
N O
A A

Sample Output 2:
No Route Available from F to Z

Problem_AM

K2 is the second-highest mountain on Earth. It is situated between Pakistan and China. It is
known as the Savage Mountain due to the difficulty of ascent and has the second-highest
fatality rate. It has never been climbed in winter. The major routes that have been climbed on
the south side of the mountain are: A: West Ridge; B: West Face; C: Southwest Pillar; D: South
Face; E: South-southeast Spur; and F: Abruzzi Spur, these are shown in the figure below:


A Pakistani mountaineer has estimated the risk associated with these routes. He has divided
the entire scene of the south side of the mountain into small square blocks of equal size. Each
square provides one handhold. The handhold has some risk associated with it. A new climber
can use his estimate to determine the least dangerous route to the top. The climber should
always start from the base of the mountain and from there move on to the block at the next
level. As shown at Figure 1, at each step, the climber has the option to continue climbing the
mountain by moving on to one out of three possible blocks, meaning the block located
diagonally on right of the current block, the block located diagonally on the left or the block
located exactly above the current block. Note that in cases where the climber is at the corner of
a column, some handholds may not be available, for example diagonal-right handhold when the
climber is already at the handhold of the right-most block.

Fig. 1. Graphical illustration of the possible moves of the climber. The current block of the
climber is highlighted in orange whereas all the possible next moves are depicted with blue
arrows.
Task
In this problem a two dimensional table describing the risks at each position of the climbing
phase would be given as input to the program and the least dangerous possible route for
reaching the top of the mountain will have to be estimated. The risks in the table are defined in a
bottom-up order meaning that the first row of the table will signify the risks associated with the
individual positions at the top of the mountain whereas the values at the last row of the table
show the corresponding risk for all the available blocks at the base of the mountain.

For any given route (i.e. path starting from the base of the mountain and leading to its top) the
overall risk associated with it will be calculated as the sum of danger ratings (costs) of all the
individual blocks used for that path.
1 2 3 1 1 1
3 1 4 5 4 5
1 2 3 3 3 1
2 3 4 1 5 5
2 4 1 5 5 5
1 2 3 3 4 1
3 5 5 2 4 5
4 5 2 3 4 5


For a better understanding, please consider the following exemplary two dimensional array
being given as input to the program.

Fig. 2 An example of all the risks associated with every single block that may be followed to
reach the top of the mountain.

Assuming a zero-based indexing scheme, the program should start from the base of the
mountain (the last row), choosing a block at each level where the possible blocks to climb from
a particular position have already been described above (see figure 1). The goal of the program
is to find an optimal path to the top of the mountain (the first row) i.e. one that has least risk
attached to it.

NOTE:
If, at any cell, there are multiple candidates for the handholds at the next level (each of which
leads to a path with the same overall risk factor), then the order of preference for handholds is:
diagonal-left > exactly-above > diagonal-right. For example, if at a particular cell, selecting either
the handhold at the next level which is exactly-above or diagonally to the right of the current one
leads to the optimal path (but not the one which is diagonally to the left), you should proceed
by moving onto the cell that is exactly above the current one, since its preference is higher than
the one to the diagonal-right. In this way, your program should always arrive at a unique minimal
risk path.
Input
The program shall receive the following input from the standard input stream:
The first line of the input will be two positive integer numbers [M, N] separated by a
space
Then M lines should follow, each one containing N positive space separated integer
values representing the risk associated in each block of the mountain from top to the
base of the row.

An example of the input format is provided below:
12 10
3 1 1 3 1 4 0 3 3 2
0 0 1 5 0 2 3 2 4 3
1 3 2 1 4 1 1 2 1 4
1 1 4 2 0 1 5 5 1 1
0 4 0 1 1 4 3 1 1 5
4 1 0 5 2 4 1 4 0 4
0 3 3 1 3 1 1 0 2 2
1 3 1 0 2 3 1 0 1 5
3 3 3 5 1 3 3 1 5 0
4 2 0 4 0 4 2 5 0 4
4 1 2 2 3 2 2 5 4 1
4 1 2 4 1 3 1 1 1 2


Output
The program should output to the standard output stream the complete path with the least
associated risk that a mountaineer should follow to reach the top of the mountain. Then a new
line should follow describing the total accumulated risk of the reported path. The output should
be formatted as follows:
Minimum risk path = [R1,C1][R2,C2][RK,CK]
Risks along the path = R where R1, C1, R2, C2 Rk, Ck are the zero-based indices of the
cells of the two dimensional array that were followed to reach the mountains peak using this
route. The first pair [R1,C1] indicates the cell at the top of the mountain whereas the last pair
[Rk,Ck] denotes the base. The first index in the pair always stands for the row and the second
for the column of each individual cell, and they are separated ONLY by a comma. Also, each
pair of indices is enclosed in square brackets and there is NO space between adjacent pairs.
The value R is the integer value corresponding to the overall risk associated to the reported
route, calculated as the sum of all the costs of the blocks used for that path.

NOTE:
The output should consist of only 2 lines. There is no new third line in the output.

An example of the output is provided below:
Minimum risk path = [0,1][1,0][2,0][3,1][4,2][5,2][6,3][7,3][8,4][9,4][10,3][11,4]
Risks along the path = 8


Sample Input:
7 7
2 2 2 1 2 3 4
2 2 1 2 1 2 5
4 1 1 2 1 1 5
1 2 2 3 3 4 1
4 1 1 2 2 1 4
3 4 1 4 1 2 1
1 2 1 1 1 2 1

Sample Output:
Minimum risk path = [0,3][1,2][2,1][3,0][4,1][5,2][6,2]
Risks along the path = 7

problem_AA

In this problem, we give you a solution. Your only task is to make it more efficient, so that you
would not hit the time limit.

def o(s):
l=len(s)
return len(set([a+b+c
for a in s for b in s for c in s])
)==l*(l+1)*(l+2)//6
M=int(input())
N=3**M
i=1
s=M*[i]
while i:
if s[i]-N:
s[i]=s[i]+1
if o(s[:i+1]):
if i<M-1:
i=i+1
s[i]=s[i-1]
else:
N=s[-1]
else:
i=i-1
print(N)




So write a program which gives the same output as the following Python program, but runs
within the time limit.
Sample Input 1:
2

Sample Output 1:
2

Sample Input 2:
4

Sample Output 2:
12

You can assume that the input is a single number n in the range 1 < n < 11


Problem_AB
IBM ponder this puzzle master needs your help to check solutions for March 2013 challenge

http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/Challenges/March2013.html

Input format
The input is at most 31 lines of the upper case letters: A,B,C,D,E

Output format:
The output is either:
Ok (if the input is a valid solution)
Too long (if there are more than 31 lines)
Err (if there exists an example of two values for the products B,C,D,E which gives the same
integrity of the points; though one of them has exactly two different values and the other does
not.)

Sample Input 1:
BCDDDDEEEE
BCCCCDEEEE
BCCCCDDDDE
BCDEE
BCDDE
BCCDE
BBCDE

Sample Output 1:
Ok

Sample Input 2:
BBBB
BBBC
BBCC
BCCC
CCCC
A
B
C
D
E
AA
BB
CC
DD
EE
ABCD
ABCE
ABDE
ACDE
BCDE
AB
AAB
AAAB
AAAAB
ABC
ABD
ABE
ACD
ACE
ADE
BCCD

Sample Output 2:
Err



IEEE HKN Problem
Members of IEEE HKN wanted to challenge the world, they released on their facebook page the
following problem:

Write a program to determine the number of binary palindromes in a given range [a;b]. A binary
palindrome is a number whose binary representation is reading the same in either forward or
reverse direction (leading zeros not accounted for). Example: the decimal number 5 (binary 101)
is palindromic.

Caution: the execution time is limited to 3 seconds.

Input:
The lower and upper bound of the range as positive 32-bit decimal integer numbers, separated
by a comma: a,b; 0<=a; a<=b; b<=2^32-1
Output:
Decimal integer, the number of binary palindromes in the given range (including the bounds)

Sample Input 1:
9,18

Sample output 1:
3


hint:
Dec Bin Palindromic

9 1001 x

10 1010

11 1011

12 1100

13 1101

14 1110

15 1111 x

16 10000

17 10001 x

18 10010




Problem_AQ
Last September, IBM research Ponder-This challenge was to provide only a winning strategy for
Bob (see http://bitly.com/Alice-Bob-Casino for details), since Alices strategy is too big. Can you
write a program which checks a solution?
Input
The number N in the first line, the number M in the second line and then 2**N lines of N bits
each
Output
A single bit:
0 if there is no compatible strategy for Alice (wring solution)
1 if there is (correct solution)


Sample Input 1:
2
1
01
00
11
11

Sample Output 1:
1



Sample Input 2:
2
2
00
00
11
11

Sample Output 2:
0



Sample Input 3:
3
1
000
100
010
110
001
101
011
111

Sample Output 3:
0



Sample Input 4:
3
1
000
100
010
110
001
101
011
011

Sample Output 4:
1

Problem_AT
The following 8086 code gets input in the AL register and computes a function in BL.
0100 E2FE LOOPW 0100
0102 50 PUSH AX
0103 5E POP SI
0104 89C3 MOV BX,AX
0106 D1E8 SHR AX,1
0108 D1D1 RCL CX,1
010A 75FA JNZ 0106
010C 91 XCHG AX,CX
010D BA0102 MOV DX,0201
0110 D1C2 ROL DX,1
0112 D1EB SHR BX,1
0114 D1D1 RCL CX,1
0116 38DE CMP DH,BL
0118 7EF6 JLE 0110
011A 38D3 CMP BL,DL
011C 7E06 JLE 0124
011E D1CB ROR BX,1
0120 D1D1 RCL CX,1
0122 D1C3 ROL BX,1
0124 28D4 SUB AH,DL
0126 4A DEC DX
0127 20D0 AND AL,DL
0129 21F2 AND DX,SI
012B 38C2 CMP DL,AL
012D 18E3 SBB BL,AH

Understand what it does, and generalize it for arbitrary long numbers.

Sample Input 1:
33


Sample Output 1:
12


Problem_AJ
Vangelis the bear has taken a liking to snowboarding and decided to go to the snowy mountains
of Nowy Sacz to try. Being an amateur as he is, he cannot control his speed. He just slides
down the hill hoping to cross the finishing line with as much speed as possible.

The hill is composed of N smaller parts and the slope of each part is represented by an integer
number. In case the number is positive, for example 5, it means this part is a downhill and
Vangelis will gain an additional speed of 5. Likewise, if the number is negative, for example -5, it
means this part is an uphill and Vangeliss speed will be reduced by 5. If the values is 0, then
that part is flat and Vangeliss speed will not be affected.

Vangelis can choose which part will be his starting point. His initial speed is always 0.

Write a program that will calculate the maximum speed Vangelis can have when crossing the
finishing line. In case Vangelis starts from the ending part his final speed will be 0.
Input Data

The first line contains the number N (where 2 N 2.000.000) which represents the number of
parts that the hill is composed of.

The second line contains N integer numbers separated by an empty character. The absolute
value of all numbers is less or equal to 2000.
The finish line is always after the last part to the right. Vangelis must always cross the finish line.
Output Data
The output is composed of one line. That line contains exactly one integer number, the
maximum speed Vangelis can have while crossing the finish line.

Sample Input 1:
9
4 16 -22 14 12 -11 9 -5 4

Sample Output 1:
23


Sample Input 2:
5
2 3 2 3 -20

Sample Output 2:
0

Problem_AK
Vangelis the bear was asked to measure the total usage of a weird tree-like directed network.
He observed that the network is composed of two trees that share the same root. On the first
tree all edges point towards the root and on the second tree all edges point away from the root.


All data enter the network from a vertice on the left and exit the netwok from a vertice on the
right. Vangelis realised that if he attaches his measuring tool to any of the vertices on the
bottleneck, he will get the total usage.

Write a program that finds all vertices where Vangelis can install his measuring tool and get a
full view of the network usage.
Input Data

The first line contains a number N (where 2 ? ? ? 200.000) which represents the number of
vertices that the network is composed of. The next N-1 lines contain two natural numbers A and
B separated by an empty character. Each couple represents a directional edge from vertice A to
vertice B. The value of all numbers is bigger than 0 and less or equal to N.
Output Data

The output is composed of as many lines as the amount of vertices on the bottleneck. Each line
contains exactly one natural number, the number of a vertices. Results should be given in an
increasing order.

Sample Input 1:
10
1 5
2 5
3 5
4 6
5 7
6 7
7 8
8 9
8 10


Sample Output 1:
7
8

IEEE University Partnership Program
Problem
An active member of the IEEE University Partnership Program has a huge collection of model
sized cars. Each car is painted in one color. He has them placed one next to the other in a line.

His friends are coming over tonight and he wants to show off his collection. He decided to
remove some cars (zero or more) from the line, so that the rest of the cars create a palindrome
with their colors.

Write a program that will calculate all possible ways our friend can create a palindrome.
Input Data
The first line contains a number N (where 1 ? ? ? 20.000) which represents the number of cars
in Vangeliss collection. The second line contains N characters. Each character is the color of a
car in the collection as they appear in the line.
Output Data
The output is composed of one line. That line contains exactly one integer number, the
maximum number of ways Vangelis can create a palindrome by removing (zero or more) cars
from the line. Since this number can be really big, present the result of the modulo of the
division of this number with the number 12.345.678.

Sample Input 1:
4
abcc

Sample Output 1:
5


Sample Input 2
4
dcec

Sample Output 2:
6


Sample Input 3:
20
XXXXXXXXXXXXXXXXXXXX

Sample Output 3:
1048575

Problem_AD
Charis and Katerina are two young children that are in love, but they want to keep it secret. So,
the emails they exchange, they try to encrypt them to avoid any person that might see the
conversation. Lets see what they have come up with, to encrypt all emails.

Firstly, only latin letters are encrypted leaving other symbols untouched (spaces, etc).

Each letter is assigned a number, A is 1, B is 2, C is 3, etc. The same goes also for small letters
too, a is 1, b is 2, c is 3, etc.

Each partner has two strings, all of which are used to encrypt and decrypt each word (up to 30
letters) of the message.

The first string (KEY1) contains only capital letters, for example Charis has
GOODMORNINGEVERYBODY (7, 15, 15, 4, 13, 15, 18, 14, 9, 14, 7, 5, 22, 5, 18, 25, 2, 15, 4,
25) while Katerina (KEY2) has GOODEVENINGTOYOUTOOO (7, 15, 15, 4, 5, 22, 5, 14, 9,
14, 7, 20, 15, 25, 15, 21, 20, 15, 15, 15) - both of which are of the same length.

The second string contains only numbers from 1 to 9. For example, Charis (NUM1) has the
string 23419584736458392039 while Katerina (NUM2) has 95837264758253647583. All
strings are of the same length.

For each word they want to send, they do the following. For example, for the word How we
have:



For the letter H (position 1 of the current word) we do (7 * 2 + 7 * 9 + 8) modulo 26, from which
we get as a result the letter H which is the 8th letter of the alphabet. Also, for the second letter,
we have (15 * 3 + 15 * 5 + 15) modulo 26 results the letter f. Finally, for the last letter we have
(15 * 4 + 15 * 8 + 23) modulo 26 to get the character v.

OK, OK! It can be easily shown that this encryption algorithm can be (easilly) cracked. Your task
is to identify the first pair* of possible strings (KEY1, NUM1, KEY2 and NUM2), with minimum
length needed, that can encrypt/decrypt all encrypted and decrypted words of the given list.

*If we concatenate KEY1 and NUM1 and KEY2 and NUM2 as one string in this order and
without spaces, and sort all possible solutions in the same list alphabetically

However, if for some reason there is no way to identify the characters of a spesific position
(maybe due to transmittion error), then character ? should be placed in that position we are
trying to crack. From the example, it is clear that small letter are encrypted as small letters and
capital letters are encrypted as capital letters, and vice versa.

Input
A list of encrypted and decrypted words (up to 50000). A fullstop in a single line terminates the
list

Output
A file with four lines containing in each line the following, KEY1, NUM1, KEY2, NUM2

Sampel Input 1: (No errors)
How Hfv
are aid
you yft
.

Sampel Output 1: (No errors)
AAA
111
CCG
857

Sampel Input 2:(An error occured in one of the words, at the last letter)
How Hfv
are aid
you yft
too tfp
.

Sampel Output 2:(An error occured in one of the words, at the last letter)
AA?
11?
CC?
85?


IEEE.tv Problem
In this problem we would like your assistance so as to put new floor in IEEE TV main floor. But
lets take everything from the beginning.

IEEE TV wants to put new tiles to your local IEEE student branch to prepare the environment for
them to shoot a documentory video about your Student branch activities. To save some money,
they would like to minimize the cost of the tiles needed. Peter is our ideal guy for the job.
Whenever he starts a new room, he starts from the most top left point and puts tiles in rows.
Whenever a row of tiles ends, he continues with the next row. However, when it comes to put a
whole tile that doesnt fit, then he tries to minimize the use of tiles in his own way. Firstly, he
tries to find the tile with minimum width from the used ones that is equal or bigger in width than
the space needed. Then he cuts that tile to that width, and then cuts again to the height he
needs, creating -probably- two other smaller tiles apart from the one he puts on the floor. If there
more than one tiles with the optimal width he can find, he uses that one that has the minimum
height that can pay the bill. Of course, if he cant find a tile that can do the job, then he gets a
new one and goes to cut it in the predetermined procedure. However, he never rotates the tiles.

Your job is to help us find how many tiles Peter needs, and foresee what unused ones will be
thrown away. You will be given a list of tiles (Auto-increment number, width, height) and a list of
rooms (one Latin character as ID, tile id, width of room, height of room) and you are requested
to A) print how rooms will be constructed (layout), B) How many tiles will be used and what
unused ones will be thrown away, per tile given, or - if there are no tiles thrown away.

Input
The first line will have two numbers.
Number of tiles (number-of-tiles <= 20)
Number of rooms (number-of-rooms <= 24)

Following to the first line, there are few lines equal to the number of tiles. Each line consists of
three numbers separated by a space.
An auto-increment number (tile-id)
Width of the tile
Height of the tile

Afterwards, there are few lines equal to the number of rooms. Each line consists of the
following:
Room id (a single Latin character)
Id of tile used for this room (tile-id)
Width of room
Height of room
Output
For each room, first print the id of the room (single Latin character) in one line, and then the
layout of that room using the character X (ASCII 88) and O (ASCII 79) to simulate the
positioning of the tiles. Each line will be ended by the character | (ASCII 124). Rooms should be
printed in the order given in the input data.
Then, for each tile, you should print its id (tile-id) in a single line. Then, how many new tiles will
be used in general, also in a single line. Finally, a list of the remaining used tiles in descending
order of width and then of height (for these that the width is the same). If there no remaining
used tiles, your program should print a dash (-) in a single line. Tiles should be printed in the
order given in the input data. Please, pay attention to the following example to understand the
structure of input and output data.

Sample input 1:
2 2
1 3 3
2 2 4
A 1 12 13
B 2 17 5

Sample output 1:
A
XXXOOOXXXOOO|
XXXOOOXXXOOO|
XXXOOOXXXOOO|
OOOXXXOOOXXX|
OOOXXXOOOXXX|
OOOXXXOOOXXX|
XXXOOOXXXOOO|
XXXOOOXXXOOO|
XXXOOOXXXOOO|
OOOXXXOOOXXX|
OOOXXXOOOXXX|
OOOXXXOOOXXX|
XXXOOOXXXOOO|
B
XXOOXXOOXXOOXXOOX|
XXOOXXOOXXOOXXOOX|
XXOOXXOOXXOOXXOOX|
XXOOXXOOXXOOXXOOX|
OOXXOOXXOOXXOOXXO|
1
18
3 2
2
11
1 3



Problem_AN
Julius Caesar (100 BC 44 BC), used a character substitution scheme to send hidden
messages to his commanders and allies. This encoding scheme, known as the Caesar cipher,
was still in active military use until less than a century ago. In this coding scheme, every
character in the original message (plaintext) is replaced by the character that cyclically occurs a
fixed number of positions later along the alphabet to create a coded message (ciphertext).

The Caesar cipher uses a secret integer known as the key, where 0 key 25. The key
determines the number of positions to shift forward along the alphabet to get ciphertext from
plaintext. The reverse operation of decoding requires an equal shift but in the opposite direction.

For encoding, key value of 0 implies no shift, that is, the plaintext is the same as the ciphertext.
The key value of 3 implies a shift three positions forward, that is, A is encoded as D, , W as Z
and Z as C. The key value of 25 implies a shift twenty five positions forward, that is, A is
encoded as Z, , Y as X and Z as Y. This is the same as a shift one position backward,
because -1 25 (mod 26),. Under ordinary conditions, the secret key is expected to be known
only to those who are authorized to have access to the plaintext. However, Caesar cipher is no
longer considered to be safe as the ciphertext can easily be broken by trying all 26 possible
keys. Once broken, the secret key used by the communicating parties can also be recovered
that not only allows access to the plaintext for that message but also compromises any future
communication that uses the same key.
Task

An antisocial organization, who call themselves Caesars Army conducts planned and
coordinated attacks on nonprofit websites. They have devised a variation of the Caesar cipher
to hide the information they exchange from law enforcement. The investigating agencies have
learnt that the scheme used by this organization has four closely guarded secret integers
blockLength, k1, k2 and k3, where 1 blockLength 10 and the variables k1, k2 and k3 carry
the same meaning as the key in Caesar Cipher explained above.

The members of the Caesars Army convert numerals in the message to words (eg. 200 to
numeral two hundred), remove all whitespace characters, special symbols, punctuation marks,
etc. from the message and then convert the resulting text to UPPERCASE. For all our purposes,
this is the plaintext that consists only of UPPERCASE characters in the alphabet (A Z). This
plaintext is then divided into blocks of size blockLength, except the last block which only
consists of the remainder of the characters. For example, if the plaintext has 20 characters and
blockLength is 3, it is divided into seven blocks first six with three characters each and the last
block with remaining two characters. These blocks are then coded using Caesar cipher first
block with key k1, the second block with k2, the third block with k3, the fourth block again with
k1, fifth with k2 and so on. The ciphertext also uses UPPERCASE characters only.

The investigating agencies have intercepted a ciphertext message exchanged recently. They
also have access to a dictionary that consists of all words that may possibly be used in the
plaintext no word in the plaintext is outside this dictionary. They are willing to share this
information with you and need your help in determining the values of the four secret integers
and in recovering the plaintext as soon as possible well in time to thwart the launch of the next
attack that this message may be about!
Input
The input shall always be 4 lines received by the standard input stream as follows:
1. The first line will be the cyphered text
2. Then a blank line should follow
3. The third line should be the number of words contained in the dictionary
4. The final line of the input will be the words contained in the dictionary, each word separated
by the next one by a white space character. The last word of the dictionary does not have a
white space character at the end

Note:
All four pieces of the input start on a new line.

Output
The output should contain values of the secret integers and the plaintext in the following order:
blockLength
k1
k2
k3
Plaintext

Note:
The output ends with a newline character.

Sample Input
ZVVVZBCQNFJMGYNCRIXVBCYAXAZNNDFERCRBBXLRVODJIUVUZTJCNMCJVYQVETZE
XCNLQWJGJBDTRCZEWXEJCDJIVIUVOTVUUNWLZAJMOYVSVENORCXACPHVEZKPCNC
DBYGVIOJRKKRTTCQNRZZZRZSJZKV

500
A ABLE ABOUT ABOVE ACT ADD ADVANCING AFTER AGAIN AGAINST AGE AGO AIR ALL
ALSO ALWAYS AM AN AND ANIMAL ANSWER ANY APPEAR ARE AREA AS ASK
ASSOCIATION AT ATTACK BACK BASE BE BEAUTY BEEN BEFORE BEGAN BEGIN
BEHIND BENEFIT BEST BETTER BETWEEN BIG BIRD BLACK BLUE BOAT BODY BOOK
BOTH BOX BOY BROUGHT BUILD BUSY BUT BY CALL CAME CAN CAR CARE CARRY
CAUSE CENTER CERTAIN CHANGE CHECK CHILDREN CITY CLASS CLEAR CLOSE
COLD COLOR COME COMMON COMPLETE CONTAIN CORRECT COULD COUNTRY
COURSE COVER CROSS CRY CUT DARK DAY DECIDE DEDICATED DEEP DEVELOP DID
DIFFER DIRECT DO DOES DOG DONT DONE DOOR DOWN DRAW DRIVE DRY DURING
EACH EARLY EARTH EASE EAT END ENOUGH EVEN EVER EVERY EXAMPLE
EXCELLENCE EYE FACE FACT FALL FAMILY FAR FARM FAST FATHER FEEL FEET FEW
FIELD FIGURE FINAL FIND FINE FIRE FIRST FISH FIVE FLY FOLLOW FOOD FOOT FOR
FORCE FORM FOUND FOUR FREE FRIEND FROM FRONT FULL GAME GAVE GET GIRL
GIVE GO GOLD GOOD GOT GOVERN GREAT GREEN GROUND GROUP GROW HAD
HALF HAND HAPPEN HARD HAS HAVE HE HEAD HEAR HEARD HELP HER HERE
HIGHHIM HIS HOLD HOME HORSE HOT HOUR HOUSE HOW HUMANITY HUNDRED I
IDEA IEEE IF IN INCH INNOVATION INTEREST IS ISLAND IT JUST KEEP KIND KING KNEW
KNOW LAND LARGE LARGEST LAST LATE LAUGH LAY LEAD LEARN LEAVE LEFT LESS
LET LETTER LIFE LIGHT LIKE LINE LIST LISTEN LITTLE LIVE LONG LOOK LOT LOVE
LOW MACHINE MADE MAIN MAKE MAN MANY MAP MARK MAY ME MEAN MEASURE
MEN MIGHT MILE MIND MINUTE MISS MONEY MOON MORE MORNING MOST MOTHER
MOUNTAIN MOVE MUCH MUSIC MUST MY NAME NEAR NEED NEVER NEW NEXT NIGHT
NO NORTH NOTE NOTHING NOTICE NOUN NOW NUMBER NUMERAL OBJECT OF OFF
OFTEN OH OLD ON ONCE ONE ONLY OPEN OR ORDER OTHER OUR OUT OVER OWN
PAGE PAPER PART PASS PATTERN PEOPLE PERSON PICTURE PIECE PLACE PLAIN
PLAN PLANE PLANT PLAY POINT PORT POSE POSSIBLE POUND POWER PRESS
PROBLEM PRODUCE PRODUCT PROFESSIONAL PULL PUT QUESTION QUICK RAIN RAN
REACH READ READY REAL RECORD RED REMEMBER REST RIGHT RIVER ROAD ROCK
ROOM ROUND RULE RUN SAID SAME SAW SAY SCHOOL SCIENCE SEA SECOND SEE
SEEM SELF SENTENCE SERVE SET SEVERAL SHE SHIP SHORT SHOULD SHOW SIDE
SIMPLE SINCE SING SIX SIZE SLEEP SLOW SMALL SO SOME SONG SOON SOUND
SOUTH SPECIAL SPELL STAND STAR START STATE STAY STEP STILL STOOD STOP
STORY STREET STRONG STUDY SUCH SUN SURE SURFACE TABLE TAIL TAKE TALK
TEACH TECHNOLOGICAL TELL TEN TEST THAN THAT THE THEIR THEM THEN THERE
THESE THEY THING THINK THIS THOSE THOUGH THOUGHT THOUSAND THREE
THROUGH TIME TO TOGETHER TOLD TOO TOOK TOP TOWARD TOWN TRAVEL TREE
TRUE TRY TURN TWO UNDER UNIT UNTIL UP US USE USUAL VERY VOICE VOWEL
WAIT WALK WANT WAR WARM WAS WATCH WATER WAY WE WEBSITE WEEK WELL
WENT WERE WEST WHAT WHEEL WHEN WHERE WHICH WHILE WHITE WHO WHOLE
WHY WILL WIND WITH WONDER WOOD WORD WORK WORLD WORLDS WOULD WRITE
YEAR YET YOU YOUNG YOUR

Sample Output
5
17
9
21
IEEEISTHEWORLDSLARGESTPROFESSIONALASSOCIATIONDEDICATEDTOADVANCING
TECHNOLOGICALINNOVATIONANDEXCELLENCEFORTHEBENEFITOFHUMANITYLETUSP
LANTOATTACKTHEIEEEWEBSITE

Note:
If you copy and paste the dictionary words into your program while testing, please make sure
that you have removed any additional white spaces and newline characters that might appear
due to the copy and paste (if any).
Problem Author: IEEE


Problem_AF
Joe and his entire College, total 1337 of them, went for a picnic. They were bored and they
planned a game. Everybody stand in a circle, each of them identifiers starting from 1 to 1337
consecutively in a circle, clockwise. The rule is that a numbering CONTAINS or DIVISIBLE by
7, will reverse the direction.

Lets elaborate the game a bit more. The identifiers of the students who yell-out successive
numbers, are: 1,2,3,4,5,6,7 (student 7 has just yell 7 and reversed the
direction),6,5,4,3,2,1,1337 (student 1337 has just yell 14 and reversed the direction),1,2,3
(student 3 has just yell 17 and reversed the direction),2,1,1337,1336, and so on. Joe has his
favorite number, and he wants to calculate where in the circle he should stand to yell that
number out loud.

Now that the game is set, Joe wants to stand a place from where he could yell his favourite
number. Would you please help Joe?

Input
First input, t, where 1 t 1000, the number of test cases. Followed by test cases in separate
line, and contains a positive integer smaller than 10100, representing Joes favorite number.

Output
Expected output for each test case, is the idenitifier which Joe should choose in the circle to yell
his favorite integer loud.


Sample Input 1:
3
10
100
1000

Sample Output 1:
4
2
1311


Problem_AG
Dumpstein, a nice robot was trapped on one side of a square board of NxN size (3 ? N ? 5,000;
rows and columns indexed from 1). To open the door on the other side, Dumpstein have to
solve a puzzle. Each test case, mission starts with moving the tile from cell (1, 1) to cell (N, N)
using only the directions right or down. Dumpstein is required to find the number of different
ways for the tile to reach using exactly K turns (we term a turn as a down move followed
immediately by a right move or a right followed immediately by a down; 0 < K < 2N-2).
Dumpstein can pass thorugh the door, if he answers all test cases and when the input is N = K
= 0.

Input
There are many test cases ( < 5,000 )
N K, positive integers
The input seizes with N = K = 0

Output

For each test case, output on a line an integer which is the result calculated. The number of
ways may be very large, so compute the solution modulo 1,000,000,007.

Sample Input 1:
4 2
4 3
5 3
0 0

Sample Output:
4
8
18

Explanation for the first test case 4 2: 4 ways are RRDDDR, RDDDRR, DRRRDD, DDRRRD (2
turns on each of them; R or D represents a right or down move respectively).


Problem_AV
A caravan is mapping a path through the desert. In the desert there are known oases that the
group plans to stop at to rest and get water. The caravan can travel no more than 5 days
without water. Your goal is to find the shortest path through the desert and indicate how many
days it will take to traverse that path.

In this problem the desert is represented by an NxM rectangular grid of squares. Traversing a
grid horizontally or vertically costs 1 day. Traversing the grid diagonally costs 1.5 days. There
are 4 types of squares in the grid, desert (D), starting point (S), oasis (+), and ending point (E).
Input: (Straight path with two oases)
The first line of input is the number of rows and number of columns in the grid. This is followed
by one line for each row in the grid. Each row line contains a single character for each square in
that row.
Output:
Number of days with one decimal place.
If there is no way to do it, the output should print
IMPOSSIBLE


Sample Input:
6 12
DDDDDDDDDDDD
DSDDDDDDDDDD
DDDD+DDDDDDD
DDDDDDD+DDDD
DDDDDDDDDDED
DDDDDDDDDDDD

Sample Output:
10.5

Hint
The path through the desert in this example starts from S at [1, 1] and proceeds 3.5 days to the
oasis at [4, 2]. The next oasis in the path is another 3.5 days to [7, 3]. The final leg of the path is
3.5 days to the end at [10, 4]. The total travel time is 10.5 days of travel.


Problem_AW
A simple substitution cipher is a method of encrypting text by replacing each character with
another character in the alphabet. Given a dictionary of words and an encrypted block of text,
crack the cipher and print out the decrypted text. The encrypted text may use words that do not
show up in the dictionary. All characters used in the encrypted text will appear at least once in a
word that is in the dictionary.
Input:
The first line of the input is the number of words in the provided dictionary. Each word in the
dictionary is on its own line following the number of words. After the dictionary a blank line will
be inserted. All text following the blank line will be the encrypted text.
Output:
The decrypted sentence all in CAPS

<h3>Example 1: All words in dictionary</h3>

Sample Input:
2
case
simple

AJWHPU GXAU

Sample Output1:
SIMPLE CASE


<h3>Example 2: Not all words in dictionary</h3> In the example below, the last word ABE is a
proper name that is not found in the dictionary. However, in the encoded text all characters used
in the name Abe (a,b,e) are encoded in other known words in the dictionary.

Sample Input 2:
5
ball
belongs
red
the
to

SJI XIL TEMM TIMUBPK SU ETI

Sample Output 2:
THE RED BALL BELONGS TO ABE

Вам также может понравиться