Beruflich Dokumente
Kultur Dokumente
main problemset
Editors:
u.swarnaprakash
Last updated: 2009-01-25 08:22:55
Preface
This electronic material contains a set of algorithmic problems, forming the archives of the Kurukshetra 09 Online Programming Contest (http://www.spoj.pl/KOPC09/), main problemset. The document can be accessed at the following URLs: in PostScript format: http://www.spoj.pl/KOPC09/problems/main.ps in Portable Document Format: http://www.spoj.pl/KOPC09/problems/main.pdf These resources are constantly updated to synchronise with the ever-changing hypertext version of the problems, and to include newly added problems. If you have obtained this document from another source, it is strongly recommended that you should download the current version from one of the aforementioned URLs. Enjoy problem-solving at the Kurukshetra 09 Online Programming Contest!
Disclaimer from the Editors. Despite our best efforts, it is possible that this document contains errors or that some of the content differs slightly from its original hypertext form. We take no responsibility for any such faults and their consequences. We neither authorise nor approve use of this material for any purpose other than facilitating problem solving at the Sphere Online Judge site; nor do we guarantee its fitness for any purpose whatsoever. The layout of the problems in this document is the copyright of the Editors named on the cover (as determined by the appropriate footers in the problem description). The content is the copyright of the respective Editor unless the copyright holder is otherwise stated in the resource section. The document as a whole is not protected by copyright, and fragments of it are to be regarded independently. No responsibility is taken by the Editors if use or redistribution of this document violates either their or third party copyright laws. When referring to or citing the whole or a fragment of this document, please state clearly the aforementioned URLs at which the document is to be found, as well as the resources from which the problems you are referring to originally came. Remarks concerning this document should be sent to the following e-mail address: contact@spoj.pl.
Table of Contents
1. 2. 3. 4. 5. 6. 7. Problem HIST2 (3436. Histogram) Problem KGSS (3693. Maximum Sum) Problem PROOT (3713. Primitive Root) Problem SNOOKER (3723. Snooker) Problem RAINBOW (3724. Rainbow Ride) Problem TREX (3725. Taming a T-REX) Problem KLUCKY (3727. Lucky Number)
3436. Histogram
Problem code: HIST2
In statistics, a histogram is a graphical display of tabulated frequencies, shown as bars. It shows what proportion of cases fall into each of several categories. It is a polygon composed of a sequence of rectangles aligned at a common base line. In this problem all rectangles have a width of unit length. But their heights are distinct. Some permutation of the heights will give the maximum perimeter. Your task is to find the maximum perimeter of the histogram and the number of permutations that give the maximum perimeter. [IMAGE] In the image Figure (a) shows a histogram with heights {1,2,3,4} (1st sample testcase) and has a perimeter of 16 units. Figure (b) shows one of the permutations {3,1,2,4} having the maximum perimeter of 20 units.
Input
Input consists of multiple test cases. Each test case describes a histogram and starts with an integer N, 2 <= N <= 15, denoting the number of rectangles it is composed of. Next line consists of N space separated positive integers representing the heights of the rectangles. All heights are distinct and less than or equal to 100. N=0 indicates the end of tests. There are atmost 50 test cases.
Output
For each test case output the maximum possible perimeter of the histogram and the number of permutations that give maximum perimeter in a single line, separated by a single space.
Example
Input: 4 1 2 3 4 3 2 6 5 0 Output: 20 8 24 2
Added by: u.swarnaprakash Date: 2008-11-29 Time limit: 4s Source limit:50000B Languages: All Resource: Kurukshetra 09 OPC
Input
The first line of input consists of an integer N representing the length of the sequence. Next line consists of N space separated integers A[i]. Next line contains an integer Q, Q <= 10^5, representing the number of operations. Next Q lines contain the operations.
Output
Output the maximum sum mentioned above, in a separate line, for each Query.
Example
Input: 5 1 2 3 4 5 6 Q 2 4 Q 2 5 U 1 6 Q 1 5 U 1 7 Q 1 5 Output:
7 9 11 12
Warning: large Input/Output data, be careful with certain languages Added by: u.swarnaprakash Date: 2009-01-10 Time limit: 2s-4s Source limit:50000B Languages: All Resource: Kurukshetra 09 OPC
Input
There will be multiple test cases. Each test case starts with two integers p ( p < 2 31 ) and n (1 <= n <= 100 ) separated by a space on a single line. p is the prime number we want to use and n is the number of candidates we need to check. Then n lines follow each containing a single integer to check. An empty line follows each test case and the end of test cases is indicated by p=0 and n=0 and it should not be processed. The number of test cases is atmost 60.
Output
For each test case print "YES" (quotes for clarity) if r is a primitive root of p and "NO" (again quotes for clarity) otherwise.
Example
Input: 5 2 3 4 7 2 3 4 0 0
Explanation
In the first test case 3 1 , 3 2 , 3 3 and 3 4 are respectively 3, 4, 2 and 1 (mod 5). So, 3 is a primitive root of 5. 4 1 , 4 2 , 4 3 and 4 4 are respectively 4, 1, 4 and 1 respectively. So, 4 is not a primitive root of 5. Added by: u.swarnaprakash Date: 2009-01-14 Time limit: 3s Source limit:50000B Languages: All Resource: Kurukshetra 09 OPC
3723. Snooker
Problem code: SNOOKER
Consider a rectangular snooker table with pockets only at the 4 corners of the rectangle as shown in the image below. Consider all integer points on the boundary of the table. At each point, except the four corners (four pockets), you are allowed to hit the ball at an angle of 45 degrees from the side of the table from which you are hitting the ball. From any point on the boundary you can hit the ball in two directions and they are considered to be two different ways. For instance in the image shown below, from the point S the ball can be hit in two ways as shown. Given the dimensions of the board your task is to find the number of ways in which the ball can be hit so that it eventually reaches one of the four holes. Consider the ball to be of negligible size, like a point. Also assume that the ball does not lose energy due to collisions or friction - it keeps moving until it drops into a hole. [IMAGE]
Input
The input has multiple test cases. Each test case consists of two space separated integers M and N, 2 <= M,N <= 10^5, representing the dimensions of the table. M=N=0 indicates the end of tests. There are atmost 300 testcases.
Output
For each test case output the number of ways as described, in a separate line.
Example
Input: 2 2 2 4 3 5 0 0 Output: 0 4 24
Added by: u.swarnaprakash Date: 2009-01-16 Time limit: 3s Source limit:50000B Languages: All Resource: Kurukshetra 09 OPC
Input
There will be multiple test cases in the input. For our convenience the family members are numbered from 1 to n. Each test case begins with a line containing two integers n ( 1 <= n <= 1000 ) and C ( 0 <= C <= 1000 ), where n is the number of people in the family and C the maximum capacity of the ride in kilograms. The next line contains n space separated integers with the ith integer giving the weight of the i th family member. These weights are positive and less than or equal to 200 kilograms. Then n lines follow. Each line contains a sequence of integers separated by spaces. The first integer k i gives the number of people in the family person i likes, followed by the persons i likes. An empty line separates each test case. The end of input is indicated by n=0 and C=0 and it should not be processed.There are atmost 50 test cases.
Output
For each test case output on a separate line the maximum number of persons that can take the ride under the given conditions.
Example
Input: 5 200 50 50 50 50 50 1 2 1 3 0 1 5 1 4 3 200 100 100 100 1 2 1 3
1 1 0 0 Output: 3 0
Added by: u.swarnaprakash Date: 2009-01-16 Time limit: 5s Source limit:50000B Languages: All Resource: Kurukshetra 09 OPC
Input
There will be multiple test cases in the input. The input begins with a line containing a single integer n,n <= 300, which gives the number of test cases. Then n lines follow each containing the three integers I, 1 <= I <= 10 6 , d, 1 <= d <= 10 5 , and C, 1 <= I <= 10 6 , in that order separated by spaces. d is in kilometers.
Output
For each test case print on a separate line the maximum number of cows that can be transported to the destination village under the given conditions.
Example
Input: 2 3000 1000 1000 30 10 10
Output: 533 5
Note: A few test cases have been added and this problem has been rejudged on January 25th, 2009.
Added by: u.swarnaprakash Date: 2009-01-17 Time limit: 5s Source 50000B limit: Languages: All Kurukshetra 09 Resource: OPC
Input
First line of input contains an integer t, t <= 200, representing the number of test-cases. Then t lines follow each containing one integer n, 1 <= n <= 8000.
Output
For each test case output the nth lucky number on a separate line. Answers will fit in a 32-bit signed integer.
Example
Input: 4 1 2 3 9 Output: 5 25 30 630
Added by: u.swarnaprakash Date: 2009-01-17 Time limit: 2s Source limit:50000B Languages: All Resource: Kurukshetra 09 OPC