Escolar Documentos
Profissional Documentos
Cultura Documentos
Whats Next
Problem code: ACPC10A
According to Wikipedia, an arithmetic progression (AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For instance, the sequence 3, 5, 7, 9, 11, 13, . . . is an arithmetic progression with common difference 2. For this problem, we will limit ourselves to arithmetic progression whose common difference is a non-zero integer. On the other hand, a geometric progression (GP) is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, . . . is a geometric progression with common ratio 3. For this problem, we will limit ourselves to geometric progression whose common ratio is a non-zero integer. Given three successive members of a sequence, you need to determine the type of the progression and the next successive member.
Input
Your program will be tested on one or more test cases. Each case is specified on a single line with three integers (10, 000 < a1 , a2 , a3 < 10, 000) where a1 , a2 , and a3 are distinct. The last case is followed by a line with three zeros.
Output
For each test case, you program must print a single line of the form: XX v where XX is either AP or GP depending if the given progression is an Arithmetic or Geometric Progression. v is the next member of the given sequence. All input cases are guaranteed to be either an arithmetic or geometric progressions.
Example
Input: 4 7 10 2 6 18 0 0 0 Output: AP 13 GP 54 Added by: Date: Time limit: Source limit: Languages: Resource: Omar ElAzazy 2010-11-30 2s 50000B All ACPC 2010
Lang=c++-4.3.2
testcase,
<=
<=
OUTPUT
Varun Jalan 2010-12-13 3s 50000B All own problem, ICPC Asia regionals, Amritapuri 2010
Your task is very simple. Given two non-negative integers N and M, you have to calculate the sum (F(N) + F(N + 1) + ... + F(M)) mod 1000000007.
Input
The
rst line contains an integer T (the number of test cases). Then, T lines follow. Each test case consists of a single line with two non-negative integers N and M.
The
first line contains an integer T (the number of test cases). Then, T lines follow. Each test case consists of a single line with two non-negative integers N and M.
Output
For each test case you have to output a single line containing the answer for the task.
Example
Input: 3 0 3 3 5 10 19 Output: 4 10 10857
Constraints
T <= 1000 0 <= N <= M <= 109
Lang=C
3407. Candy
Problem code: SAMER08C
Little Charlie is a nice boy addicted to candies. He is even a subscriber to All Candies Magazine and was selected to participate in the International Candy Picking Contest. In this contest a random number of boxes containing candies are disposed in M rows with N columns each (so, there are a total of M N boxes). Each box has a number indicating how many candies it contains. The contestant can pick a box (any one) and get all the candies it contains. But
there is a catch (there is always a the rows immediately above and box to the left and the box to continues to pick a box until there
catch): when choosing a box, all the boxes from immediately below are emptied, as well as the the right of the chosen box. The contestant are no candies left.
The figure bellow illustrates this, step by step. Each cell represents one box and the number of candies it contains. At each step, the chosen box is circled and the shaded cells represent the boxes that will be emptied. After eight steps the game is over and Charlie picked 10+9+8+3+7+6+10+1 = 54 candies.
For small values of M and N, Charlie can easily find the maximum number of candies he can pick, but when the numbers are really large he gets completely lost. Can you help Charlie maximize the number of candies he can pick?
Input
The input contains several test cases. The first line of a test case contains two positive integers M and N (1 M N 105), separated by a single space, indicating the number of rows and columns respectively. Each of the following M lines contains N integers separated by single spaces, each representing the initial number of candies in the corresponding box. Each box will have initially at least 1 and at most 103 candies. The end of input is indicated by a line containing two zeroes separated by a single space.
Output
For each test case in the input, your program must print a single line, containing a single value, the integer indicating the maximum number of candies that Charlie can pick.
Example
Input:
5 5 1 8 2 1 9 1 7 3 5 2 1 2 10 3 10 8 4 7 9 1 7 1 3 1 6 4 4 10 1 1 10 1 1 1 1 1 1 1 1 10 1 1 10 2 4 9 10 2 7 5 1 1 5 0 0 Output: 54 40 17
Diego Satoba 2008-11-23 2s 50000B C C++ 4.3.2 C++ 4.0.0-8 JAVA PAS fpc PAS gpc South American Regional Contests 2008
Lang=c++4.0.0-8
3410. Feynman
Problem code: SAMER08F
Richard Phillips Feynman was a well known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and also pioneered the field of quantum computing. He visited South America for ten months, giving lectures and enjoying life in the tropics. He is also known for his books "Surely You're Joking, Mr. Feynman!" and "What Do You Care What Other People Think?", which include some of his adventures below the equator. His life-long addiction was solving and making puzzles, locks, and cyphers. Recently, an old farmer in South America, who was a host to the young physicist in 1949, found some papers and notes that is believed to have belonged to Feynman. Among notes about mesons and electromagnetism, there was a napkin where he wrote a simple puzzle: "how many different squares are there in a grid of N N squares?". In the same napkin there was a drawing which is reproduced below, showing that, for N=2, the answer is 5.
Input
The input contains several test cases. Each test case is composed of a single line, containing only one integerN, representing the number of squares in each side of the grid (1 N 100). The end of input is indicated by a line containing only one zero.
Output
For each test case in the input, your program must print a single line, containing the number of different squares for the corresponding input.
Example
Input: 2 1 8 0 Output: 5 1 204
Diego Satoba 2008-11-23 1s 50000B C C++ 4.3.2 C++ 4.0.0-8 JAVA PAS fpc PAS gpc South American Regional Contests 2008
Lang=JAVA
1163. Java vs C ++
Problem code: JAVAC
Apologists of Java and C++ can argue for hours proving each other that their programming language is the best one. Java people will tell that their programs are clearer and less prone to errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them that their programs are slow and have long source code.
Another issue that Java and C++ people could never agree on is identifier naming. In Java a multiword identifier is constructed in the following manner: the first word is written starting from the small letter, and the following ones are written starting from the capital letter, no separators are used. All other letters are small. Examples of a Java identifier are javaIdentifier, longAndMnemonicIdentifier, name, nEERC.
Unlike them, C++ people use only small letters in their identifiers. To separate words they use underscore character _. Examples of C++ identifiers are c_identifier, long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++ people agree), n_e_e_r_c.
You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of course, identifiers in the translated program must be formatted due to its language rules otherwise people will never like your translator.
The first thing you would like to write is an identifier translation routine. Given an identifier, it would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is neither, then your routine should report an error. Translation must preserve the order of words and must only change the case of letters and/or add/remove underscores.
Input
The input file consists of several lines that contains an identifier. It consists of letters of the English alphabet and underscores. Its length does not exceed 100.
Output
If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java version. If it is none, output 'Error!' instead.
Example
Input: long_and_mnemonic_identifier anotherExample i bad_Style Output: longAndMnemonicIdentifier another_example i Error! Added by: Camilo Andrs Varela Len
language=c++4.0,0.0-8
You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...10000.
Input
The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.
Output
For each point in the input, write the number written at that point or write No Number if there is none.
Example
Input: 3 4 2 6 6 3 4 Output: 6 12 No Number Added by: Date: Time limit: Source limit: Languages: Resource: Camilo Andrs Varela Len 2006-11-25 2s 50000B All except: ERL JS PERL 6 Asia - Tehran 2000
language=C
In the above diagram, the first term is 1/1, the second term is 1/2, the third term is 2/1, the fourth term is 3/1, the fifth term is 2/2, and so on.
Input
The input starts with a line containing a single integer t <= 20, the number of test cases. t test cases follow. Then, it contains a single number per line.
Output
You are to write a program that will read a list of numbers in the range from 1 to 10^7 and will print for each number the corresponding term in Cantor's enumeration as given below.
Example
Input: 3 3 14 7 Output: TERM 3 IS 2/1 TERM 14 IS 2/4 TERM 7 IS 1/4 Added by: Date: Time limit: Source limit: Languages: Resource: Thanh-Vy Hua 2005-02-27 5s 50000B All except: PERL 6 ACM South Eastern European Region 2004
language=C
Input
The first line of the input contains an integer t, the number of test cases. t test cases follow. Each test case consists of a single line containing a single integer k (1 <= k <= 2000000000000).
Output
For each test case, output a single integer which denotes the kth number whose cube ends in 888. The result will be less than 263.
Example
Input: 1 1 Output: 192
language=C++4.0.0-8
Matthew Reeder 2006-10-30 5s 30000B All except: ERL JS PERL 6 Al-Khawarizm 2006
Input
The first line of the input contains an integer t, the number of test cases. t test cases follow. Each test case consists of 3 lines: The first line contains a single integer N (1 <= N <= 1000). The second line contains N integers separated by single spaces denoting the hotness levels of the men. The third line contains N integers separated by single spaces denoting the hotness levels of the women.
Output
For each test case output a single line containing a single integer denoting the sum of the hotness bonds for all pairs that MMDS has proposed.
Example
Input: 2 2 1 1 3 2 3 2 3 2 1 3 2 Output: 5 15 Added by: Date: Time limit: Source limit: Languages: Resource: Matthew Reeder 2006-10-29 2s 30000B All except: ERL JS PERL 6 Al-Khawarizm 2006
language=C
1786. In Danger
Problem code: DANGER
Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he calculated the position to be the last man standing (and then he did not commit suicide since nobody could watch). We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest!
Input Specification
The input contains several test cases. Each specifies a number n, denoting the number of persons participating in the game. To make things more difficult, it always has the format "xyez" with the following semantics: when n is written down in decimal notation, its first digit is x, its second digit is y, and then followz zeros. Whereas 0<=x,y<=9, the number of zeros is 0<=z<=6. You may assume that n>0. The last test case is followed by the string 00e0.
Output Specification
For each test case generate a line containing the position of the person who survives. Assume that the participants have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2. For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 is staying alive.
Sample Input
05e0 01e1 42e0 66e6 00e0
Sample Output
3 5 21 64891137 Added by: Date: Time limit: Source limit: Langua ges: Wanderley Guimares 2007-09-19 1s 50000B All except: ERL JS University of Ulm Local Contest 2004
Input
The input contains at most 10 lines, each line consists of no more than 100000 lowercase letters, representing a string.
Output
The length of the longest common substring. If such string doesn't exist, print "0" instead.
Example
Input: alsdfkjfjkdsal fdjskalajfkdsla aaaajfaaaa Output: 2 Notice: new testcases added
apple packet. A value of -1 denotes that the corresponding packet is unavailable. 0 < N <= 100 0 < K <= 100 0 < price <= 1000 Output The output for each test case should be a single line containing the minimum amount of money he has to spend for his friends. Print -1 if it is not possible for him to satisfy his friends. Sample I/O: Input: 2 35 -1 -1 4 5 -1 55 12345 Output: -1 5 Explanation of test cases: 1) As there are only 3 and 4kg packets in the shop, he will not be able to satisfy his friends as he would not be able to buy exactly 5kg of apples. 2) He can buy five 1kg packet as he has to buy 5 kg. So the min money he should spend is 5.
Kashyap 2012-01-13 1s
Languages: Resource:
2178. He is offside!
Problem code: OFFSIDE
Hemisphere Network is the largest television network in Tumbolia, a small country located east of South America (or south of East America). The most popular sport in Tumbolia, unsurprisingly, is soccer; many games are broadcast every week in Tumbolia. Hemisphere Network receives many requests to replay dubious plays; usually, these happen when a player is deemed to be offside by the referee. An attacking player is offside if he is nearer to his opponents goal line than the second last opponent. A player is not offside if he is level with the second last opponent or he is level with the last two opponents.
Through the use of computer graphics technology, Hemisphere Network can take an image of the field and determine the distances of the players to the defending teams goal line, but they still need a program that, given these distances, decides whether a player is offside.
Input
The input file contains several test cases. The first line of each test case contains two integers A and D separated by a single space indicating, respectively, the number of attacking and defending players involved in the play (2 <= A,D <= 11). The next line contains A integers Bi separated by single spaces, indicating the distances of the attacking players to the goal line (1 <= B i <= 104). The next line contains D integers Cjseparated by single spaces, indicating the distances of the defending players to the goal line (1 <= Cj <= 104). The end of input is indicated by A = D = 0.
Output
For each test case in the input print a line containing a single character: Y
Example
Input: 2 3 500 700 700 500 500 2 2 200 400 200 1000 3 4 530 510 490 480 470 50 310 0 0 Output: N Y N
Input
The first line of the standard input contains one integer t (t<10001) which is the number of test cases. In each of the next t lines there is number n (0<=n<=5*10^9).
Output
For each test, print the length of n! (which is factorial of n).
Example
Input: 3 1 10 100 Output: 1 7 158 len(n!)=ceiling(log10(1)+log10(2)+.+log10(n))
A 7-seg has seven connectors, one for each element, (plus few more connectors for other electrical purposes.) Each element can be turned on by sending an electric current through its pin. Each of the seven pins is viewed by programmers as a single bit in a 7-bit number, as they are more comfortable dealing with bits rather than electrical signals. The figure below shows the bit assignment for a typical 7-seg, bit 0 being the right-most bit.
For example, in order to display the digit 1, the programmer knows that only bits 1 and 3 need to be on, i.e. the 7-bit binary number to display digit 1 is "0001010", or 10 in decimal. Let's call the decimal number for displaying a digit, its display code, or just code for short. Since a 7-seg displays 127 different configurations, display codes are normally written using 3 decimal places with leading zeros if necessary, i.e. the display code for digit 1 is written as 010. In a 9-digit calculator, 9 7-seg displays are stacked next to each other, and are all controlled by a single controller. The controller is sent a sequence of 3n digits, representing n display codes, where 0 < n < 10 . If n < 9 , the number is right justified and leading zeros are automatically displayed. For example, the display code for 13 is 010079 while for 144 it is 010106106 Write a program that reads the display codes of two numbers, and prints the display code of their sum.
Input
Your program will be tested on one or more test cases. Each test case is specified on a single line in the form of A+B= where both A and B are display codes for decimal numbers a and b respectively where 0 < a , b < a + b < 1, 000, 000, 000 . The last line of the input file is the word "BYE" (without the double quotes.)
Output
For each test case, print A+B=C where C is the display code for a + b .
Example
Input: 010079010+010079= 106010+010= BYE Output: 010079010+010079=010106106 106010+010=106093
Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 ANARC 2008
A word is called a palindrome if we read from right to left is as same as we read from left to right. For example, "dad", "eye" and "racecar" are all palindromes, but "odd", "see" and "orange" are not palindromes. Given n palindromes, you can generate n n pairs of them and concatenate the pairs into single words. The task is to count how many of the so generated words are palindromes.
Input
The first line of input file contains the number of strings n. The following n lines describe each string: The i+1-th line contains the length of the i-th string li, then a single space and a string of li small letters of English alphabet. You can assume that the total length of all strings will not exceed 2,000,000. Two strings in different line may be the same.
Output
Print out only one integer, the number of palindromes.
Example
Input: 3 1 a 2 bb 2 aa Output: 5 The 5 palindromes are: aa aaa aaa bbb aaaa
Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 POI 2006
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 iteventually 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.
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
Swarnaprakash 2009-01-16 3s
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 106, d, 1 d 105, and C, 1 I 106, 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.
Swarnaprakash 2009-01-17 5s
Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 Kurukshetra 09 OPC
2906. GCD2
Problem code: GCD2
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm int gcd(int a, int b) {
if (b==0) return a; else return gcd(b,a%b); } and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 digits. Your task is to help Frank programming an efficient code for the challenge of Felman.
Input
The first line of the input file contains a number representing the number of lines to follow. Each line consists of two number A and B (0 <= A <= 40000 and A <= B < 10^250).
Output
Print for each pair (A,B) in the input one integer representing the GCD of A and B.
Example
Input: 2 2 6 10 11 Output: 2 1
Frank Rafael Arteaga 2008-08-04 0.5s 1000B All except: C99 strict LISP sbcl LISP clisp ERL JAVA JS PERL PERL 6 PHP PYTH 2.5 RUBY My own Resource
902. Hangover
Problem code: HANGOVER
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples. Input: 1.00 3.71 0.04 5.19 0.00 Output: 3 card(s) 61 card(s) 1 card(s) 273 card(s)
Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 ACM Mid Central Regionals 2001
Input
The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow. For each test case will appear a and b separated by space.
Output
For each test case output an integer per line representing the result.
Example
Input: 2 3 10 6 2 Output: 9 6
Languages: Resource:
1. Last digit of
; ;
2. Determine the cyclicity number 3. Find the remainder 4. When digit of when
divided by the cyclisity; is the same as that of , where and when , then last
Integer ending with 0, 1, 5 or 6, in the integer power k>0, has the same last digit as the base. Integers ending with 2, 3, 7 and 8 have a cyclicity of 4. Integers ending with 4 (eg. and when n is even ) have a cyclisity of 2. When n is odd will end with 4
will end with 6. ) have a cyclisity of 2. When n is odd will end with 9
Example: What is the last digit of Solution: Last digit of cyclisity of 1. 7^1=7 2. 7^2=9 3. 7^3=3 4. 7^4=1 (last (last (last (last : digit digit digit digit is is is is 7) 9) 3) 1)
Now divide 39 (power) by 4 (cyclisity), remainder is 3.So, the last digit of as that of the last digit of . , is the same as that of the last digit of
10 2 53
Hari
2009-12-27
Time limit:
1s
Input
The first line of the input contains a number t (about 10^5), the number of the test cases. The next t lines contain a number x (1 <= x <= 10^9).
Output
Output a total of t lines with each line containing the value n corresponding to the input case.
Example
Input: 2 1 7 Output: 3 10
2 3 3 1 2 5 2 3
8 6 1
Output:
2 5
Added by: Date: Time limit: Paranoid Android 2010-03-06 5s