Problem F Chessboard Coloring You have a chessboard with N rows and N columns. You want to color each of the cells with exactly N colors (colors are numbered from 0 to N 1). A coloring is valid if and only if no row or no columns contains a duplicate color. That means in the final coloring each cell should be colored by a color from 0 to N 1. No row will contain two cells of the same color and same for the no column. Your friend already colored some of the cells in the top left corner (cells that are in the first R row and in the first C columns). Your job is to color the rest of the cells or tell it is impossible to color. starts with an integer T(1 T 50), the number of test cases. Each test case starts with a line containing integers N(1 T 50), R (0 R N) and C (0 C N). Each of the next R line contains C integers in each line. The j th integer in the i th line indicates the color of the cell located at row i and column j. The initial coloring will be always valid. That means No row or column will have duplicate integers. The initial colors are between 0 to N 1 inclusive. For each test case output YES when it is possible to color the rest of the cells or NO otherwise. YES 2 2 NO 1 2 YES 2 0 2 0 1 2 2 0 1 1 1 0
Problem G Half Nim Half Nim is a 2 player game in which player take turns removing stones from distinct heaps. There are N heaps with a 1,a 2,,a n number of stones. The player is permitted to take any positive number of stones from one pile for a move but no more than half. The player who cannot make his move loses. Given the number of stones in the piles you are to determine if the first player has a winning strategy. You can assume that both of the players play perfectly. starts with an integer T(1 T 100), the number of test cases. Each test case starts with a line containing N(1 N 100) the number of heaps. Next line contains N integers a 1,a 2,,a n. These numbers are between 1 and 2*10 18 inclusive. For each test case output contains a line in the format Case #x: M where x is the case number (starting from 1) and M will be YES if the first player wins and NO if the first player cannot win. 2 1 2 2 6 Case #1: NO Case #2: YES Case #: NO
Problem H Point inside a Polygon Given a test point and the vertices of a simple polygon, vertices, determine if the test point is in the interior, in the exterior or on the boundary of the polygon. For simplicity, all sides of the polygon will be horizontal or vertical, and the vertices and the test point will all be at integer coordinates. A simple polygon is a polygon that may or may not be convex, but self intersection is not allowed. Not even at a single point. First line of the input contains T the number of test cases. Each test case starts with a line containing N the number of points of the polygon. N is between and 100 inclusive. Each of the next N line contains 2 integers X and Y the co ordinate of a vertex of the polygon. The vertices will be given in order. No three consecutive points will be collinear. The final line will contain 2 integers TX and TY denoting the coordinate of the test point. All the co ordinates are between 1000 to +1000 inclusive. For each test case, output INTERIOR if the point is inside the polygon, EXTERIOR if the point is outside the polygon and BOUNDARY if the point is on the boundary of the polygon. 0 10 10 10 1 5 5 0 10 10 10 1 10 15 0 10 10 10 1 5 10 10 0-2 -2 0-1 0-1 2 2 1 0 1 1 2 INTERIOR EXTERIOR BOUNDARY EXTERIOR
Problem I Spiral Consider all positive integers written in the following manner (you can imagine an infinite spiral). 21 22 2 2 25 26 20 7 8 9 10... 19 6 1 2 11... 18 5 12... 17 16 15 1 1... You task is to determine the position (row,column) of a given number N, assuming that the center (number 1) has position (0,0). Rows are numbered from top to bottom, columns are numbered from left to right (for example, number is at (1,1)). Your program should ouput a string containing the position of N in form (R,C) where R is the row and C is the column. R and C must not contain any leading zeroes. The first line of the input gives an integer T, which is the number of test cases. Each test case contains an integer N (1 N<2^1). For each test case, output the position as described above. See sample output for further clarification. 7 2 7 17 2 80 76509 (0,1) (1,1) (-1,-1) (2,-2) (-2,1) (-1,) (-7,221)
Problem J Guitar Game You have been invited to a TV game show where you will play against another contestant to win free guitars. At the start of the game, there are n guitar cases arranged in a circle, each of which contains a single guitar. You make the first move by choosing one guitar and removing it from its case. The other player then chooses a guitar and removes it from its case. At this point, there might be one or two groups, where a group is defined as a maximal contiguous set of non empty cases. You continue to take turns choosing guitars, and on each turn, the current player chooses exactly one guitar from each group. The game ends when all the guitars have been chosen. Each player gets to keep all the guitars that he chooses during the game. Your goal is to maximize the total value of the guitars you choose. The guitars in the circle are numbered 0 to n 1 in clockwise order (guitar 0 is next to guitar n 1). Given the values of the guitars, compute the maximum possible total value you can get, assuming your opponent plays a perfect strategy. First line of the input contains T the number of test cases. Each test case starts with a line containing N, the number of guitars. N is between 2 and 100 inclusive. Next line contains N integers denoting the values of the guitars. All the values are between 1 and 10000 inclusive. For each test case output the maximum possible total value you can get, assuming your opponent plays a perfect strategy. 6 5 1 5 5 8 8 2 1 1 2 1 8 1 5 12 5 10 5 7 8 8 2 2 8 2 2 Sample 10 12 12 22 1 16
Problem K Marbles in a Bag Your friend Psycho Sid has challenged you to a game. He has a bag containing R red marbles and B blue marbles. There will be an odd number of marbles in the bag, and you go first. On your turn, you reach into the bag and remove a random marble from the bag; each marble may be selected with equal probability. After your turn is over, Sid will reach into the bag and remove a blue marble; if there is no blue marble for Sid to remove, then he wins. If the final marble removed from the bag is blue, you will win. Otherwise, Sid wins. Given the number of red and blue marbles in the bag, determine the probability that you win the game. The first line of the input gives an integer T, which is the number of test cases. Each test case contains 2 integers R and B. Both R and B are between 0 and 000 inclusive. R+B will always be odd. For each case, output the probability that you win the game. digits after the decimal. 1 2 2 2 5 11 Sample 0. 0.1 0.228571 0.1218