• View
205

• Category

Documents

Embed Size (px)

Basic DivisionProblem 1: Prime Palindromes, (K Narayan Kumar, CMI) An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 are palindromes. In this task you will be given an integer N, 1 N 1000000. You must find the smallest integer M N such that M is a prime number and M is a palindrome. For example, if N is 31 then the answer is 101. Input format A single integer N, (1 N 1000000), on a single line. Output format Your output must consist of a single integer, the smallest prime palindrome greater than or equal to N. Example We now illustrate the input and output formats using the example described above. Sample input:31

Sample output:101

Basic DivisionProblem 2: The Lead Game, (K Narayan Kumar, CMI) The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient. The game consists of several rounds and in each round both players obtain a score, based on how well they played. Once all the rounds have been played, the total score of each player is determined by adding up the scores in all the rounds and the player with the higher total score is declared the winner. The Siruseri Sports Club organises an annual billiards game where the top two players of Siruseri play against each other. The Manager of Siruseri Sports Club decided to add his own twist to the game by changing the rules for determining the winner. In his version, at the end of each round the leader and her current lead are calculated. Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner. Consider the following score sheet for a game with 5 rounds:Round Player 1 Player 2

1 2

140 89

82 134

3 4 5

90 112 88

110 106 90

The total scores of both players, the leader and the lead after each round for this game is given below:Round Player 1 Player 2 Leader Lead

1 2 3 4 5

140 229 319 431 519

82 216 326 432 522

Player 1 Player 1 Player 2 Player 2 Player 2

58 13 7 1 3

The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1) during the game. Your task is to help the Manager find the winner and the winning lead. You may assume that the scores will be such that there will always be a single winner. That is, there are no ties. Input format The first line of the input will contain a single integer N (N 10000) indicating the number of rounds in the game. Lines 2,3,...,N+1 describe the scores of the two players in the N rounds. Line i+1 contains two integer Si and Ti, the scores of the Player 1 and 2 respectively, in round i. You may assume that 1 Si 1000 and 1 Ti 1000. Output format Your output must consist of a single line containing two integers W and L, where W is 1 or 2 and indicates the winner and L is the maximum lead attained by the winner. Test Data The range of values over which your program is to be tested is mentioned above. In addition, 50% of the test cases will also satisfy N 1000. Example We now illustrate the input and output formats using the example described above. Sample input:5 140 82 89 134 90 110

112 106 88 90

Sample output:1 58

Basic DivisionProblem 1: BCCS Elections, (K Narayan Kumar, CMI) The Board of Cricket Control of Siruseri holds an election every year to elect a 3 member executive committee to run the affairs of the board. The executive committee is quite powerful, as it decides which television company gets to broadcast the Siruseri Cricket League and so on. The procedure for this election is the following. All those interested in serving as executive committee members inform the Manager. The Manager informs all the members of the BCCS about the list of candidates. On the day of the election, each member of BCCS is allowed to vote for exactly one of the candidates. Finally all the votes are counted and the top three candidates are deemed elected. Suppose there are 5 candidates {1,2,3,4,5}, 10 members in all in BCCS and the votes cast are as follows:Voter Vote

1 2 3 4 5 6 7 8 9 10

2 5 4 4 3 1 2 1 1 2

Then, candidates 1, 2 (with 3 votes each) and 4 (with 2 votes) are elected to the executive committee. You are given the number of candidates and voters and the list of votes. Your task to determine the candidate finishing third. You may assume that the votes are cast in such a way that there is never a tie between the second and third best candidates or between the third and fourth best candidates.

Input format The first line of the input consists of two integers C and N, where C is the number of candidates and N is the number of voters. The next N lines, lines 2,..., N+1, provide information on the votes. Line i+1, 1 i N, contains a single integer Vi, 1 Vi C, indicating the choice of voter i. Output format The output must consist of a single line with a single integer, indicating the identity of the candidate finishing third. Test data You may assume that 3 N 100000 and 3 C 10000. Example We now illustrate the input and output formats using the example described above. Sample input:5 10 2 5 4 4 3 1 2 1 1 2

Sample output:4

Basic DivisionProblem 2: A Board Game, (K Narayan Kumar, CMI) In this task you have to determine the outcome of a board game. The board on which the game is played has N places labelled 1,2,...,N. Each position is marked with either a + or a -. The position 1 is always marked with a +. A token is initially placed at position 1. The game proceeds as follows: In each round, a single die is thrown. Let the current position of the token be j and let the die show d. The new position of the token is determined as follows:

If the position j is labelled + and if j+d N then the token moves to j+d, otherwise it remains at j. If the position j is labelled - and if j-d 1 then the token moves to j-d, otherwise it remains at j

The score at the end of the game is the number of times the token visits the position 1. For example if the board looks like1 + 2 + 3 4 + 5 6 7 + 8 9 10 + 11 12 -

and the sequence of throws of the die is 1,1,2,3,2,6,3,2,6,2 then the sequence of positions visited by the token is 1 2 3 1 4 6 6 3 1 7 9 and the resulting score is 3. You are given the description of the board and a sequence of throws of the die. Your aim is to determine the score at the end of the game. Input format The first line contains two integers N and M where N is the number of positions on the board and M is the number of throws of the die. Lines 2,...,N+1 contain a + or a -. Line i+1, 1 i N, indicates whether position i is marked with a + or a -. The next M lines, lines N+2,..., N+1+M, each contain a single integer d indicating a throw of the die, with 1 d 6. Output format A single integer indicating the score. Test Data You may assume 7 N 10000 and 1 M 10000. Example We now illustrate the input and output formats using the example described above. Sample input:12 + + + + 10

+ 1 1 2 3 2 6 3 2 6 2

Sample output:3

Basic DivisionProblem 1: The Lazy Circus Gymnast, (K Narayan Kumar, CMI) One of the highlights of the shows of the Ennui Circus Company is the performance by Palli, "The Incredible Lizard Man". As his stage name suggests, Palli can climb up and down any vertical surface - trees, walls, ropes, ... For his performance, a set of smooth steel cylinders of varying heights are arranged in a line. Palli then climbs up to the top of each of these cylinders. To save himself some work (and to make the show interesting) he does not climb all the way down from a cylinder to move to the next. If the next cylinder is taller than the present one, he simply jumps across horizontally from the top of the current cylinder, latches onto the side of the next one and climbs up from there. If the next cylinder is shorter than the present one, he comes down from the top of the current cylinder till he is at the same level as the top of the next one and then jumps across horizontally. Palli is very lazy and he would like to minimize the amount of climbing up and down that he has to do during his show. He has a limited choice in this matter because the circus owner has already purchased the set of cylinders to be used. All that Palli can do is to rearrange these cylinders in any sequence he wants. He would like to choose an arrangement that minimizes his work. For example, suppose there are three cylinders C1, C2 and C3, of heights 4, 2 and 4 metres, respectively. If he chose to arrange them in the order C1 C2 C3 then he would have to climb 12 metres (4 metres to reach the top of C1, descend 2 metres, jump to the top of C2, jump across to C3, climb 2 metres to reach the top of C3 and finally climb down 4 metres from the top of C3,

adding up to 12 metres). Instead, if he were arrange these cylinders in the sequence C3 C1 C2 then he only needs to climb 8 metres. Your task is to help him find an arrangment of the cylinders that minimizes the amount he has to climb up and down. Input format The first line of the input consists of an integer N indicating number of cylinders. The next N lines (i.e. lines 2,..., N+1) provide information on the heights of the cylinders. Line i+1, (1 i N) contains a single integer hi, indicating the height of cylinder i. Output format The output must consist of N lines, each containing one integer ai (1 ai N), so that the sequence a1 a2 ... aN describes a optimal way of arranging the cylinders 1,...,N. If there is more than one optimal arrangement, it suffices to print any one. Test data You may assume that 3 N 5000. Example We now illustrate the input and output formats using the example described above. Sample input:3 4 2 4

Sample output:3 1 2

Basic DivisionProblem 2: Find the Numbers, (K Narayan Ku

Recommended

Documents
Documents
Documents
Documents
Presentasi MoodUs for Nokia Lumia Apps Olympiad
Entertainment & Humor