Documente Academic
Documente Profesional
Documente Cultură
Tim is an absolutely obsessive soda drinker, he simply cannot get enough. Most annoyingly though, he almost never has any money, so his only obvious legal way to obtain more soda is to take the money he gets when he recycles empty soda bottles to buy new ones. In addition to the empty bottles resulting from his own consumption he sometimes nd empty bottles in the street. One day he was extra thirsty, so he actually drank sodas until he couldnt aord a new one.
Input
Three non-negative integers e, f , c, where e < 1000 equals the number of empty soda bottles in Tims possession at the start of the day, f < 1000 the number of empty soda bottles found during the day, and 1 < c < 2000 the number of empty bottles required to buy a new soda.
Output
How many sodas did Tim drink on his extra thirsty day? standard input 9 0 3 5 5 2 4 9 standard output
Page 1 of 8
Input
On the rst line of the input is a positive integer, the number of test cases. Then for each test case: A line containing two positive integers h, w 50, the height and width of the maze. h lines of w characters each, the map of the cavern our protagonist made, in which: # is a wall or otherwise impassible space. . is an empty space, of which there are at most 100. S is our protagonist. X is one of the heavy sarcophagi. There are at most two of these. B is a button. E is the exit. There is exactly one exit, on the edge of the map. The edge of the map contains only walls and the exit. Page 2 of 8
Output
For each test case: One line containing the minimum number of steps2 it will take S to escape the tomb, or the text impossible if she cannot escape.
Page 3 of 8
Input
The rst line of input gives 1 n 1000 and 0 m 10000, the number of cities and roads. Then follows a line with ith city. Then follow m lines with three integers 0 u, v < n and 1 d 100, telling that there is a road between uand v with length d. Then comes a line with the number 1 q 100, giving the number of queries, and q lines with three integers 1 c 100, s and e, where c is the fuel capacity of the vehicle, s is the starting city, and e is the goal.
Output
For each query, output the price of the cheapest trip from s to e using a car with the given capacity, or impossible if there is no way of getting from s to e with the given car.
Page 4 of 8
Misha is currently interested in undirected graphs that contain no two simple cycles sharing exactly one edge. Lets call them beautiful graphs. He wants to nd the maximal beatiful graph, that is the beautiful graph that contains the most edges among all beautiful graphs with at most n vertices. But Misha is going to leave on vacation, so he asked you to help him with this problem.
Input
The input le contains a single integer n(1 n 100) the maximum number of vertices your graph can contain
Output
Output the number of vertices V (1 V n) and the number of edges E of your graph to the rst line of the output le, separated with a space. Then output E lines with two integer numbers each, again separated with a space. The two numbers should be the numbers of the vertices connected by the corresponding edge. The vertices of the graph are numbered from 1 to V . You can output edges in any order. If there are several maximal graphs, output any.
Page 5 of 8
A while ago I had trouble sleeping. I used to lie awake, staring at the ceiling, for hours and hours. Then one day my grandmother suggested I tried counting sheep after Id gone to bed. As always when my grandmother suggests things, I decided to try it out. The only problem was, there were no sheep around to be counted when I went to bed. Creative as I am, that wasnt going to stop me. I sat down and wrote a computer program that made a grid of characters, where # represents a sheep, while . is grass (or whatever you like, just not sheep). To make the counting a little more interesting, I also decided I wanted to count ocks of sheep instead of single sheep. Two sheep are in the same ock if they share a common side (up, down, right or left). Also, if sheep A is in the same ock as sheep B, and sheep B is in the same ock as sheep C, then sheeps A and C are in the same ock. Now, Ive got a new problem. Though counting these sheep actually helps me fall asleep, I nd that it is extremely boring. To solve this, Ive decided I need another computer program that does the counting for me. Then Ill be able to just start both these programs before I go to bed, and Ill sleep tight until the morning without any disturbances. I need you to write this program for me.
Input
The rst line of input contains a single number T , the number of test cases to follow. Each test case begins with a line containing two numbers, H and W , the height and width of the sheep grid. Then follows H lines, each containing W characters (either # or .), describing that part of the grid.
Output
For each test case, output a line containing a single number, the amount of sheep ocks on that grid according to the rules stated in the problem description. Notes and Constraints 0 < T 100 0 < H, W 100
Page 6 of 8
The path consisting of streets labeled with 9s seems to be faster at the rst sight. However, due to the braking and accelerating restrictions, it takes double the estimated time for every street on the path, making the total time 108. The path along the streets labeled with 10s is faster because Johnny can drive two of the streets at the full speed, giving a total time of 100.
Input
The input consists of several test cases. Each test case starts with six positive integer numbers: R , C , r1 , c1 , r2 , and c2 . R and C describe the size of the city, r1 , c1 are the starting coordinates, and r2 , c2 are the coordinates of Johnnys home. The starting coordinates are dierent from the coordinates of Johnnys home. The numbers satisfy the following condition: 1 r1 , r2 R 100 , 1 c1 , c2 C 100 . After the six numbers, there are C - 1 non-negative integers describing the time needed to drive on streets between intersections (1,1) and (1,2), (1,2) and (1,3), (1,3) and (1,4), and so on. Then there Page 7 of 8
Bolivian Summer Training Camp Patacamaya Saturday, February 27, 2010 are C non-negative integers describing the time need to drive on streets between intersections (1,1) and (2,1), (1,2) and (2,2), and so on. After that, another C - 1 non-negative integers describe the next row of streets across the width of the city. The input continues in this way to describe all streets in the city. Each integer species the time needed to drive through the corresponding street (not higher than 10000), provided the steam roller proceeds straight through without starting, stopping, or turning at either end of the street. If any combination of one or more of these events occurs, the time is multiplied by two. Any of these integers may be zero, in which case the corresponding street cannot be used at all. The last test case is followed by six zeroes. All numbers are separated with at least one whitespace character (space, tab, or newline), but any amount of additional whitespace (including empty lines) may be present to improve readability.
Output
For each test case, print the case number (beginning with 1) followed by the minimal time needed to go from intersection r1 , c1 to r2 , c2 . If the trip cannot be accomplished (due to unusable streets), print the word Impossible instead.
Page 8 of 8