You are on page 1of 6

KNUTH JIIT PROGRAMMING HUB

PRESENTS

EXECUTE 12.2
The coding combat

Bail Walter
PROBLEM STATEMENT: Walter is been locked inside the St. Claire's Mental Institution for 17 years now. Olivia and Peter have come to Bail him out because they need him to save the world. In order to get out of the Mental Institution, Walter needs to prove that he is mentally stable. The head of St. Claires Mental Institution gives Walter a String s and asks him to tell the lexicographically largest subsequence of s. For Strings x and y, we say y is a subsequence of x if y can be obtained from x by erasing some (possibly all or none) of the letters in x. For example, "rnge" is a subsequence of "fringe", while "gef" is not. Help Walter answer this easy question with help of a program. NOTE: For strings x and y, x is said to be lexicographically larger than y if y is a prefix of x or y has a smaller character than x at the first position where they differ. Order of characters is defined as the order of ASCII codes: 'a' < 'b' < ... < 'z'. INPUT: The first line of input contains an integer T, the number of test cases. Then T lines follow, each containing a string s. OUTPUT: For each test case, output on a newline the lexicographically largest subsequence of s. CONSTRAINTS: 1<=T<=160 1<=Length(s)<=50 Each character in s will be a lowercase letter ('a'-'z') SAMPLE INPUT: 4 test a fringe aquickbrownfoxjumpsoverthelazydog SAMPLE OUTPUT: tt a rnge zyog TIME LIMIT: 1 sec EXPLANATION: Case #1: All subsequences listed in lexicographical order are (empty string), e, es, est, et, s, st, t, te, tes, test, tet, ts, tst and tt. So answer is tt. Case #2: There are only two subsequences, and a.

Big Bang Pizza Trouble


PROBLEM STATEMENT: Sheldon, Leonard, Howard and Rajesh order pizza from Giacomos every Thursday. Sheldon orders his with sausage, mushrooms, and light olive, and he prefers the shape of the pizza to be a convex polygon with n + 2 sides. Leonard decides to cut the pizza into triangles by cutting along a straight line joining two vertices. But before he cuts the pizza into triangle slices, Sheldon must know the exact number of different ways in which these slices can be cut according to Leonards method. Given Sheldons smartness, he still needs your help. Help him find the answer for a given value of n. The answer can be very large so print the answer modulo 1000000007. INPUT: The first line of input contains an integer T, the number of test cases. Then T lines follow, each containing an integer n. OUTPUT: For each test case, output on a newline the number of different ways to cut the pizza with n+2 sides into triangles by cutting along a straight line joining two vertices. CONSTRAINTS: 1<=T<=1000 1<=n<=1000 SAMPLE INPUT: 5 1 2 3 4 18 SAMPLE OUTPUT: 1 2 5 14 477638700 TIME LIMIT: 1 sec EXPLANATION: For Case #4: There are 14 different ways as shown below.

Wave Sink Device Fight


PROBLEM STATEMENT: Walter and Walternate are fighting over the Wave Sink Device in order to fix their own universes. Of course, the Observers have formed the rules to this fight. According to the Observers, the entire Space-Time continuum is assumed to infinitely linear with centre point Z. Initially both Walter and Walternate will stand on the centre Z of this Space-Time continuum, facing each other. Don't worry there is enough space to hold Walter and Walternate at the same place and at the same time. Walter can jump either A or B units to the left or right in one move. Walternate can jump either C or D units to the left or right in one move. The Observers want to place the Wave Sink Device within this Space-Time continuum, such that both Walter and Walternate will be able to reach it independently in one or more moves. Also the Wave Sink Device can be placed at most K units from the centre of the Space-Time continuum. The Observers will let you watch this fight if you can decide the number of possible positions in this Space-Time continuum where this Device can be placed. NOTE: The number of moves of Walter can differ from the number of moves of Walternate. INPUT: The first line of input contains an integer T, the number of test cases. Then T lines follow, each containing five integers, A B C D K. OUTPUT: For each test case, output on a newline, the number of possible positions to place the Wave Sink Device within the Space-Time continuum. CONSTRAINTS: 1<=T<=1000 1<=A,B,C,D,K<=10^18 SAMPLE INPUT: 3 24367 12451 10 12 3 9 16 SAMPLE OUTPUT: 3 3 5 TIME LIMIT: 1 sec EXPLANATION: Case #2: Walter jumps 2 units to the right and then 1 unit to the left. Walternate jumps 5 units to the right and then 4 units to the left to reach 1 unit right from the centre. Walter jumps 2 units to the left and then 1 unit to the right. Walternate jumps 5 units to the left and then 4 units to the right to reach 1 unit left from the centre. The Wave Sink Device can also be placed at the centre as Walter and Walternate can reach it in 2 moves. (e.g. X units to the left or right and then X units back to the centre) Thus, there are three different positions that are reachable by both Walter and Walternate in one or more moves.

Lannister v/s Targaryen


PROBLEM STATEMENT: The Lannister and Targaryen armies are fighting each other in the Games of Thrones. You are the leader of the Targaryen army and you have to win the war. You and your opponent will line up your respective units in two rows, with each of your units facing exactly one of your opponent's units and vice versa. Then, each pair of units, who face each other, will fight and the stronger one will be victorious, while the weaker one will be captured. If two opposing units are equally strong, your unit will lose and be captured. You know how the Lannister army will arrange its units, and must decide how to line up yours. You want to maximize the sum of the strengths of your units that are not captured during the battle. NOTE: Both the armies will have the same number of units. INPUT: The first line of input contains an integer T, the number of test cases. Then 3*T lines follow. The first line for each test case contains an integer N, the number of units in both armies. The second line contains N integers ti (i from 1 to N) denoting the strength of the individual units of your army. The third line contains N integers li (i from 1 to N) denoting the strength of the individual units of Lannister's army. OUTPUT: For each test case, output on a newline, the maximum total strength of your units that are not captured. CONSTRAINTS: 1<=T<=70 1<=N<=50 1<=ti,li<=1000 SAMPLE INPUT: 4 5 5 15 100 1 5 5 15 100 1 5 6 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 10 1 3 5 7 9 11 13 15 17 19 2 4 6 8 10 12 14 16 18 20 10 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 SAMPLE OUTPUT: 120 0 99 65 TIME LIMIT: 1 sec EXPLANATION: Case #1: Your units with strength of 100 and 15, and 5 can avoid capture. Hence their sum is 120.

Jones Teleporter
PROBLEM STATEMENT: David Robert Jones has built himself a teleporter device and he can teleport himself from one hotspot and another hotspot and vice versa. The hotspots are linked with each other via wormholes through which he teleports himself. One hotpot may be connected with multiple hotspots via these wormholes. Hotspots which are not connected to any other hotspots may also exist. Given the configuration of hotspots, Jones wants to know whether it is possible to teleport from one hotspot A to another hotspot B. INPUT: The first line of input contains an integer T, the number of test cases. Then T test cases follow. First line of each test case contains two space separated integers N and M, denoting number of hotspots and the number of wormholes. Then M lines follow each containing two space separated integers A and B, denoting that there is a wormhole between hotspots A and B. Assume that hotspots are indexed by numbers from 0 to N-1. Next line contains an integer Q denoting the number of queries. Each of the next Q lines contains two integers X and Y. For each query you have to find out if Jones can teleport between hotspot X and hotspot Y. OUTPUT: For each test case print Q lines - one for each query. Output "DISINTEGRATE" if Jones can teleport between the given hotspots and "FREEZE" otherwise (quotes for clarity). NOTE: Teleportation from source to destination can be via intermediate hotspots. There might be multiple wormholes between same pair of hotspots, also there might be a wormhole that links a hotspot to itself. If X=Y, the answer is DISINTEGRATE. CONSTRAINTS: 1<=T<=10 1<=N<=100 1<=M<=600 0<=A,B,X,Y<=N-1 1<=Q<=600 SAMPLE INPUT: 1 42 01 12 3 02 03 21 SAMPLE OUTPUT: DISINTEGRATE FREEZE DISINTEGRATE TIME LIMIT: 3 sec WARNING: Use Fast I/O Methods

You might also like