Problem Statement | |||||||||||||
| Nick likes to draw fractals. For the special occasion of Single Round Match 500, he decided to draw the 500th generation of his favorite fractal.
Each generation of the fractal can be described as a set of segments on the plane. Some of these segments are called final and all other are considered to be non-final. In each non-final segment, one of its endpoints is chosen and called the root of this segment. In pictures below, solid and dotted lines are used to represent final and non-final segments, correspondingly. The first generation consists of one segment with endpoints (0, 0) and (0, 81). This segment is non-final and its root is (0, 0).
The i-th generation, i >= 2, is produced from the (i-1)-th generation as follows. All final segments from the (i-1)-th generation are included into the i-th generation without any changes. For each non-final segment from the (i-1)-th generation, let A and B be its endpoints, with A being its root. The following steps are then done:
Consider a rectangle R on the plane that consists of points (x, y), such that x1 <= x <= x2 and y1 <= y <= y2. Let S be the set of all segments of the 500-th generation of the fractal described above (both final and non-final ones). Return the total length of all parts of segments from S that belong to rectangle R. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The returned value must have an absolute or relative error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | x1 will be between -100 and 100, inclusive. | ||||||||||||
| - | x2 will be between x1+1 and 100, inclusive. | ||||||||||||
| - | y1 will be between -100 and 100, inclusive. | ||||||||||||
| - | y2 will be between y1+1 and 100, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | ||||||||||||||||||||||||
| In this problem you will be given a large graph formed by a random process. You will then be asked to find a series of subgraphs of ever-increasing size. Your task is to answer as many queries as possible before time runs out. An undirected graph G = (V,E) is defined by a set of vertices, V, indexed from 0 to N-1 and a set of edges (u,v). As the graph is undirected, each edge will be listed in both directions. An induced subgraph H of G is defined by a subset of vertices V' and all of the edges in E where both u and v are in V'. See Wikipedia for a more rigorous definition. In the induced subgraph isomorphism problem, you are given two graphs: a graph G with N vertices, and a graph H with K vertices. Your task is to find a mapping f() from 0..K-1 to 0..N-1 such that (u,v) is an edge in H if and only if (f(u), f(v)) is an edge in G. Again, see Wikipedia for a formal definition. In this problem, you will be given a graph G, followed by a series of smaller graphs H5, H6, H7, ... (starting from H5 intentionally). Hi will be an induced subgraph of G on i vertices. For each such query, you should return a int[] with i elements, where element j of your return represents f(j) above. Each graph input will be formatted as a single int[]. The first element of the array will give the number of vertices. The degrees of the nodes will then be listed one at a time, along the their lists of neighbors. Thus, the following pseudocode will decode the input: ptr = 0 vertices = input[ptr++] for (i = 0; i < vertices; i++) degree = input[ptr++] for (j = 0; j < degree; j++) createEdge(i, input[ptr++])where createEdge(u,v) creates an edge in whatever data structure you choose to use. ScoringYou will be given 10 seconds of total execution time. A function initialize will take the large graph G, and should return an integer (it doesn't matter what you return here). A function query will then be called repeatedly, starting with H5. Your 10 seconds includes the time spent in these functions (both initialize and query). Your query function will be called until you either run out of time, or give an incorrect return (one that isn't a match, or isn't valid). Your score for each test case will simply be the number of queries answered correctly before time runs out (or an incorrect return). Your overall score for all test cases will be the sum of your scores on all the individual test cases.Test GenerationThe graph G will be generated by first picking three values: N, alpha, and D. N will be chosen uniformly at random in [1000,20000]. Alpha will be a floating point number uniformly at random in [1,3). D will be an integer chosen uniformly in [2,30].For vertex i, a location (xi,yi) will be chosen with xi and yi each integers in [0,220). For each vertex i, we will then generate D undirected edges (i,j). Given a choice of i, each j will be chosen with probability proportional to (1+dist(i,j))-alpha, where dist(i,j) = sqrt((xi-xj)2 + (yi-yj)2). The choices of j will be made with replacement, so the same j may be chosen multiple times. After all selection are made, duplicates are eliminated, leaving a simple undirected graph. To select each Hi, a seed vertex u will be chosen uniformly at random from the N vertices in G. All neighbors of u will be added to the set of frontier vertices. Then, a node is chosen randomly from the set of frontier vertices and all of its neighbors are added to the frontier. A node added to the frontier multiple times will have multiple chances to be selected (making the frontier a multiset). This process is repeated until i vertices are chosen. If the frontier set becomes empty before i vertices have been selected, the select process is restarted from scratch. Finally, the subgraph is extracted and the vertex labels are randomly shuffled. Offline ToolAn offline testing tool is provided here. | ||||||||||||||||||||||||
Definition | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
Notes | ||||||||||||||||||||||||
| - | The time limit is 10 seconds. | |||||||||||||||||||||||
| - | The memory limit is 1024MB. | |||||||||||||||||||||||
| - | Your method will be queried until you run out of time, or until the size of the subgraph is equal to the largest connected component in G. | |||||||||||||||||||||||
| - | There are 50 test cases. | |||||||||||||||||||||||
Examples | ||||||||||||||||||||||||
| 0) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 1) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 2) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 3) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 4) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 5) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 6) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 7) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 8) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 9) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Consider a circle in the plane. You are given an int places. This is the number of places that are equally spaced along the perimeter of the circle, i.e., the distance between any two consecutive places is equal. The places are numbered 0 to places-1 in clockwise order, starting at an arbitrary place. We will now draw red points in some of the places. The number of red points is given as an int points. As the number of points may be large, we will generate them using a simple process that is described below. Finally, once all points are generated, your task is to find and return the number of right triangles that have all three vertices in red points. To generate the points, you are given three ints a, b, and c. For n = 0, 1, 2, 3, ..., points-1, execute the following steps:
| |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | A right triangle is a triangle with non-zero area in which one of the angles is exactly 90 degrees. | ||||||||||||
| - | For any valid input the answer fits into a long (i.e., a signed 64-bit integer variable). | ||||||||||||
Constraints | |||||||||||||
| - | places will be between 1 and 1,000,000, inclusive. | ||||||||||||
| - | points will be between 0 and 100,000, inclusive. | ||||||||||||
| - | points will not be greater than places. | ||||||||||||
| - | a will be between 0 and 1,000,000, inclusive. | ||||||||||||
| - | b will be between 0 and 1,000,000, inclusive. | ||||||||||||
| - | c will be between 0 and 1,000,000, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| An ancient clay tile was found during an archeological dig. It could have been an important find, but unfortunately it is broken into pieces which are shuffled and shabby, so in its current state it has hardly any importance. You have to reconstruct the original look of the tile from its pieces.
The original tile is generated as a highly symmetrical shape which fits inside of an S x S square. This is done as follows: one eighth of the tile is generated as a random polygon. Then the polygon is filled with random pattern, created as a set of lines of random orientation and width. Finally, the generated one eighth of the tile is reflected symmetrically with respect to axes x=y and the result is rotated by 90 degrees three times to fill all the tile. See the visualizer source code for more details. The generated tile is broken into pieces using a Voronoi diagram of a random set of points within the tile. Some of these pieces are removed, and the edges of the rest are crumbled up randomly. Note that the original edges of the tile generally don't crumble: the pixels on them can crumble if they belong to the border of the S x S square and to the crack between two pieces at the same time, or if after the main crumbling process they have 1 or 0 pixels of the same piece adjacent to them. Finally, the resulting pieces are rotated randomly and presented to you as a String[] pieces. The format of pieces is as follows: each piece is a sequence of individual Strings representing its rows, and the consecutive pieces are separated with "-" Strings. The pixels where there is no clay are represented with '.', and black and white clay pixels are represented with '1' and '0' characters, respectively. Besides, you are given S - the size of the square and N - the number of pixels in the original tile. Your task is to restore the original tile as an S x S square, with black and white pixels represented in the same way as in the input. You have to arrange the pieces in some way and fill the spaces between them with clay pixels of any color. Note that you don't need to distinguish the parts which are covered with the actual pieces from the parts which are lost or crumbled, you only have to reconstruct the whole image as close to the original one as possible. Your score for an individual test case will be calculated as follows: the original tile and the one you returned are compared pixel-by-pixel; for each pixel which is absent ('.') on both tiles or present on both tiles in the same color you score 1, and for each pixel which is present on both tiles but has different colors you score 0.5. Finally, the sum of scores for individual pixels is divided by S*S. Your overall score will be the sum of scores over all test cases. A visualizer is available for visualization and offline testing. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Invalid return (i.e., sized not S x S or containing characters other than '.', '0' and '1') gives you a score of 0. | ||||||||||||
| - | Please see visualizer source for details of test case generation. | ||||||||||||
| - | The memory limit is 1024 MB and the time limit is 20 seconds (which includes only time spent in your code). There is no explicit code size limit. | ||||||||||||
| - | There are 10 example test cases and 100 full submission test cases. | ||||||||||||
Constraints | |||||||||||||
| - | S will be up to 401. | ||||||||||||
| - | Up to one fifth of the pieces will be removed. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
| 7) | |||||||||||||
| |||||||||||||
| 8) | |||||||||||||
| |||||||||||||
| 9) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
IntroductionAirlines have to perform routine maintenance on their fleets. However, they do not want this maintenance to interrupt their flight schedules. You work for AAFE (An Airline that Flies Everywhere) and have been tasked with scheduling the AAFE maintenance crew.AAFE has N planes in its fleet. Every day, each plane flies a number of routes, ending the day at some location. As the airline flies everywhere, the planes end up scattered all over the world, sometimes even landing in the ocean or at the poles (the planes are all equipped for this). The maintenance crew can service one plane per night, and getting to the correct location during the day is never a problem. However, they are paid per km traveled (in addition to a base salary and generous healthcare package) so AAFE would like for them to travel as little as possible. Furthermore, if they travel more than 4500km in one day, they will be paid double. ProblemYour task is thus to determine a schedule for the maintenance crew under which the crew travels as little as possible. The crew will start at a home location (as specified by latitude and longitude) and must service one as-yet-unserviced plane per night for the next N nights. After the final plane has been serviced, the crew will return home for one night off before the next maintenance cycle begins. Night is used loosely in this context, as the crew will end up in many different timezones, and night refers to night UTC.Implementation DetailsYou will be given an int N, indicating the number of planes, and an int M indicating the number of cycles. You will also be given the crew's home location as two doubles, start_lat and start_lng. The schedule for the N planes will be given to you as a single double[]. The simulation will have (N+1)*M nights for the M cycles of N planes plus one night off per cycle. The input will thus contain 2 * N * (N+1)*M elements. The ending latitude of plane j on night i of the simulation will be given by element 2 * (i * N + j) of the input. The longitude will be the next element: 2 * (i * N + j) + 1.The planes are numbered 0..N-1. You should return a int[] with N*M elements indicating the planes to be served in each cycle. The first N elements of your return should be a permutation of the integers 0..N-1, as should the next N and so on. For example, imagine that there are two planes and two maintenance cycles (N=M=2). The input might look like
{
10, 0, 40, -90, //ending locations for two planes on day 0
20, 105, -25, 43 //day 1
-20, -15, -65, -143 //day 2
50, -45, -35, 13 //day 3
10, -175 , 15, 74 //day 4
-5, -85, 25, 18 //day 5
}
Imagine that the maintenance crew starts at 0,0. They need to service planes
at the end of days 0,1, 3, and 4. If they service plane 0 on nights 0 and 4,
and plane 1 on nights 1 and 3, then their route would be:
0,0 -> 10,0 -> -25,43 -> 0,0 -> -35,13 -> 10,-175 -> 0,0In this case, you would return {0,1,1,0}. ScoringThe average cost, AVG, of travel by the crew is determined by the first finding the great circle distance (km) between consecutive points on the crew itinerary. Any of those that are 4500km or more will then be doubled. The average of these costs is then taken. Your score for each individual test case will be 10000/AVG. Your overall score will simply be the sum of your individual scores. If you fail a test case (your program doesn't return an answer, or your answer is invalid) you will receive a 0 for that test case.Visualizer/Offline TesterYou may download a tool to aid your development at http://www.topcoder.com/contest/problem/MaintainPlanes/vis.html.Environment & Target ConfigurationNVIDIA Tesla C1060 with 4GB of Global MemoryIntel Q8200 CPU 4GB of system memory Centos 5.3 Linux NVIDIA GeForce GPU for graphics Your application should use NVIDIA CUDA 2.3 SDK. gcc, g++, CUDA 2.3 drivers, tookit and SDK are installed on the servers, and execution path and Library paths setup. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Latitude values will be between -90 and 90, inclusive. | ||||||||||||
| - | Longitude values will be between -180 and 180, inclusive | ||||||||||||
| - | The Earth is treated as a perfect sphere with radius 6378.1km. | ||||||||||||
| - | The distance between two points is calculated as the great circle distance | ||||||||||||
| - | Note that this problem uses degrees, not radians. | ||||||||||||
| - | There are 50 provisional tests. | ||||||||||||
| - | M and N are chosen uniformly. All of the landing points are chosen uniformly over the surface of the earth. | ||||||||||||
Constraints | |||||||||||||
| - | N will be between 30 and 100, inclusive. | ||||||||||||
| - | M will be between 5 and 30, inclusive. | ||||||||||||
| - | The time limit is 20 seconds per test case. | ||||||||||||
| - | The CPU memory limit is 1024MB. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
| 7) | |||||||||||||
| |||||||||||||
| 8) | |||||||||||||
| |||||||||||||
| 9) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Your friend is going to the mountains on vacation. He will climb up and down several mountains, and he has asked you to calculate his total walking distance. To simplify this task, everything will be represented on a 2-dimensional cartesian plane. The ground is represented as the x-axis, and the mountains are represented as the union of several isosceles triangles. You are given int[]s start and finish. For each index i, construct an isosceles right triangle with its hypotenuse lying on the ground from point start[i] to point finish[i]. ![]() The mountains are guaranteed to form a single connected non-degenerate polygon, where the height is positive everywhere between the start and end points. The path your friend will walk is defined as the upper part of this mountain, shown in bold in the figure above. Return the length of this path. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The returned value must be accurate to within a relative or absolute value of 1E-9. | ||||||||||||
| - | An isosceles right triangle is a triangle with angles 90, 45 and 45 degrees. The hypotenuse of such a triangle is the side opposite the 90 degree angle. | ||||||||||||
Constraints | |||||||||||||
| - | start will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | start and finish will contain the same number of elements. | ||||||||||||
| - | Each element of start and finish will be between -1000 and 1000, inclusive. | ||||||||||||
| - | For every i start[i] will be strictly less than finish[i]. | ||||||||||||
| - | The union of the isosceles triangles described in start and finish will be a single connected nondegenerate polygon. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||||
| There is a NxN maze where each cell contains either a wall or empty space. You are currently in the top-left cell at coordinates (0, 0) and your goal is to reach the bottom-right cell at coordinates (N-1, N-1) making as few turns as possible. You can choose any of the four cardinal directions as your starting direction. Then, from each cell, you can either move forward one cell in your current direction or turn left or right by 90 degrees. You can only walk into empty cells, not walls. You are given ints M, X0, Y0, A, B, C and D. Generate lists X and Y, each of length M, using the following recursive definitions: X[0] = X0 MOD P X[i] = (X[i-1]*A+B) MOD P (note that X[i-1]*A+B may overflow a 32-bit integer) Y[0] = Y0 MOD P Y[i] = (Y[i-1]*C+D) MOD P (note that Y[i-1]*C+D may overflow a 32-bit integer) Cell (x, y) of the maze contains a wall if and only if it is neither the top-left cell nor the bottom-right cell and there exists a value of i between 0 and M-1, inclusive, such that x=X[i] MOD N and y=Y[i] MOD N. Return the minimum number of turns you must make to reach the bottom-right cell of this maze, or return -1 if it is impossible. | |||||||||||||||
Definition | |||||||||||||||
| |||||||||||||||
Notes | |||||||||||||||
| - | In the statement, "A MOD B" represents the remainder of integer division of A by B. For example, 14 MOD 5 = 4 and 20 MOD 4 = 0. | ||||||||||||||
| - | The author's solution does not depend on any properties of the pseudorandom generator. It would solve any input of allowed size within the given limits. | ||||||||||||||
Constraints | |||||||||||||||
| - | N will be between 2 and 500, inclusive. | ||||||||||||||
| - | M will be between 0 and 1,000,000, inclusive. | ||||||||||||||
| - | X0, Y0, A, B, C and D will each be between 0 and 1,000,000, inclusive. | ||||||||||||||
| - | P will be between 1 and 1,000,000, inclusive. | ||||||||||||||
Examples | |||||||||||||||
| 0) | |||||||||||||||
| |||||||||||||||
| 1) | |||||||||||||||
| |||||||||||||||
| 2) | |||||||||||||||
| |||||||||||||||
| 3) | |||||||||||||||
| |||||||||||||||
| 4) | |||||||||||||||
| |||||||||||||||
| 5) | |||||||||||||||
| |||||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| Grille cipher is a technique for encrypting a message by writing its letters onto a sheet of paper through a pierced piece of paper called grille.
To encrypt a message, the grille is placed on a gridded (for convenience) sheet of paper. The letters of the message are written in the cells of the grid which are located under the holes of the grille in order from top to bottom, from left to right. If the length of the message is greater than the number of the holes of the grille, the grille is rotated, and the rest of the message is written in the same way in the cells which are still empty. Finally, the grille is removed, and the rest of the grid is filled with random letters to complicate breaking the cipher. The encrypted message can be decrypted by using the same grille and reading the characters visible through its holes in the same order. You have intercepted a sheet of paper with a grid of letters on it which looks like it's a message encoded with a grille cipher. Your task is to construct a grille which decodes the grid into a message which makes as much sense as possible. You will be given a String[] grid which represents an NxN grid of 'A'-'Z' characters. You must return a String[] which represents an NxN grille, with '.' denoting a hole in the grille and 'X' denoting unpierced paper. Your grille can have at most H holes in each row and each column. The grille you return will be scored in the following way. First, the message is retrieved by concatenating the parts of it which are read by applying the grille straight, rotated 90, 180 and 270 degrees clockwise in order. For each grille position, the letters of the grid which are placed under the holes of the grille are read in rowwise order, the letters of one row being read from left to right. After that the message is partitioned into dictionary words and unused letters. The partition is scored as follows: each maximal contiguous sequence of dictionary words not separated with unused letters adds (number of characters in the sequence)1.1 to the score, and each unused letter subtracts 0.33 from the score. The score for a test case is the maximal score over all possible partitions. Your overall score will be the sum of your individual scores, divided by the greatest score achieved by anyone for that test case. Test cases are generated by choosing grid size N randomly between 5 and 50 and filling an NxN grid with 'A'-'Z' letters. Each letter is chosen randomly accordingly to the distribution of letters in the words of the dictionary. H is chosen randomly between 1 and floor(N/3). The visualizer is available. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | For more details on the test case generation and scoring implementation see the visualizer source. | ||||||||||||
| - | Any kind of invalid return results in a zero score for this test case. | ||||||||||||
| - | The memory limit is 1 GB and the time limit is 20 seconds (which includes only time spent in your code). | ||||||||||||
| - | The source code size limit is 300KB. | ||||||||||||
| - | There are 10 example test cases and 100 full submission test cases. | ||||||||||||
| - | You can get the dictionary at runtime by calling the library method Dictionary.getWords() that returns the list of words ordered alphabetically. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
| 7) | |||||||||||||
| |||||||||||||
| 8) | |||||||||||||
| |||||||||||||
| 9) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| Rendering a computer generated image is a huge research area, with many
aspects. In this problem we will focus on one aspect of this problem:
rendering glass objects. In particular, you will be given the locations of a
number of glass ellipsoids and a number of
light sources. Each light source will cast some amount of pure, single
frequency light, uniformly in every direction. Each of the ellipsoids will have an index of refraction of 2, which determines the way light interacts with it (we will assume an index of refraction of 1 for the air around the ellipsoids). To make things simpler, we will ignore the effects of polarization in this problem. When a ray of light strikes the surface of an ellipsoid (either from within or without) some of the light is transmitted through the surface, and some is reflected off the surface. The angle of the reflected light ray is given by the law of reflection. The angle of the refracted light is given by Snell's law. To determine what fraction of the light is reflected and what fraction is transmitted, we use the Fresnel equations. Since we are ignoring polarization, we will always be using a reflection coefficient of R = (RS+RP)/2. It is important to note that in some cases we have total internal reflection. Your task here is to render a scene from a camera at (500,500,500) pointed in the -z direction. The camera has a view angle of 90 degrees. The only object in the scene other than the glass ellipsoids is a square surface spanning from (0,0,0) to (1000,1000,0). Your should return a double[] with one million elements, representing a 1000x1000 image from the camera. Pixel (x,y) should give the intensity of a ray pointed from the camera to the point (x+0.5,y+0.5). It is easiest to think about the rendering process in terms of a two-stage ray tracer. To do this, we first calculate the intensity of light at each location on the square surface. Once this is done, we then consider a ray leaving the camera, towards a part of the scene. If the ray from the camera strikes the square surface, our task is now easy, as we've already computed the intensity of the surface. If, however, it strikes an ellipsoid, we can use the same equations mentioned above to determine the fractional contribution from the part of the light that passes through the surface and the contribution of the reflected light. It is important to note that the lights do not have any impact in the second stage. A good way to think about it is that the lights serve to illuminate the square surface in stage one, are then turned off, and the camera is turned on, while the square surface remains illuminated. You will be given a String[] ellipsoids, describing the location and size of each ellipsoid. Each element will be formatted as "CENTERx CENTERy CENTERz A B C", describing an ellipsoid ((x-CENTERx)/A)2 + ((y-CENTERy)/B)2 + ((z-CENTERz)/C)2 = 1. You will also be given a String, lights, each element of which is formatted as "X Y Z", describing a light. Your task is to return a double[], where element x*1000+y is the intensity of light observed by the camera when looking towards (x+0.5,y+0.5) -- a raster image, in other words. When comparing your image to the reference image, the first thing we will do is normalize the image so that the average intensity of the pixels in the image is 1.0. Once this is done, we will compute the error of each pixel as abs(sqrt(YOU)-sqrt(REFERENCE)). Your score for an image will be the sum of the errors for the pixels in the image, plus 5% per second of computation. Your overall score will be computed using relative scoring. If the best score for a particular scene is BEST, and you score YOU, your score for that scene will be BEST/YOU. Getting StartedWriting a ray tracer is no easy task, so to help you get started, a C implementation of this problem is being provided (it is designed to work offline -- it is not a submission). It works by picking a random direction, and emitting a single ray of light from each of the light sources in that direction. When a ray of light hits a surface, two recursive calls are made, one for the ray passing through the surface (unless there is total internal refraction) and one for the ray of light reflected off the surface. The intensities of these rays are scaled appropriately. This is continued until the intensity of the light drops below a threshold, or a maximum recursive depth is reached, or the ray strikes the square surface. The total intensity of the rays striking the surface in each 1x1 grid cell is accumulated. After a large number of random rays are emitted, the second stage of the algorithm starts. A ray is directed from the camera to each of the locations, and again when it hits a surface two recursive calls are made. If the ray hits the surface, the intensity of the 1x1 grid cell it strikes is recorded.You may freely discuss how this implementation works in the forums, so long as you do not suggest or discuss improvements. Test generationThe tests are generated by first picking N and M, the number of ellipsoids and lights, respectively. N ellipsoids are then randomly placed, where each one is placed so that it does not intersect with any of the others. The M lights are then placed so that none of them are inside any of the ellipsoids. The centers of the ellipsoids are randomly chosen as points in the view area. The 3 size parameters are chosen between 10 and 100. The ellipsoids will not intersect the square surface. The lights are chosen to have z coordinate between 200 and 500. The generation code can be found at http://www.topcoder.com/contest/problem/RayTracer/Generate.java. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Because your return will be scaled to have an average intensity of 1, that absolute scale does not matter. | ||||||||||||
| - | The reference images are created using a ray tracer which is much slower than your must be. | ||||||||||||
| - | The time limit for each image is 10 seconds. | ||||||||||||
| - | The grayscale images are created using the square root of intensity, as this gives a better visual. | ||||||||||||
| - | The memory limit is 1024M and there is no code size limit. | ||||||||||||
| - | Higher quality reference images (with less aliasing) are currently rendering. | ||||||||||||
Constraints | |||||||||||||
| - | There will be between 1 and 5 light sources, inclusive. | ||||||||||||
| - | There will be between 1 and 50 ellipsoids, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| You are playing a game where you must traverse a rectangular grid of cells using a spiral path. The map is given in a String[] levelMap, where the j-th character of the i-th element is the number of points associated with the cell in row i, column j. Rows are numbered from top to bottom, starting at 0, and columns are numbered from left to right, starting at 0. All coordinates in this problem will be given as (row, column). You start at cell (0,0), the top left corner of the grid. You are facing right. You move by repeating the following strategy until you have visited every single cell on the grid exactly once. If there is an adjacent cell in front of you that you haven't visited yet, move forward to that cell. Otherwise, if there are still unvisited cells on the grid, turn 90 degrees clockwise. To calculate your final score, add up all the points for the cells that you visited, but don't include the cells in which you changed direction. The first and last cells in your path will always be included in your final score. See examples for further clarification. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | levelMap will contain between 2 and 50 elements, inclusive. | ||||||||||||
| - | All elements of levelMap will contain the same number of characters. | ||||||||||||
| - | Each element of levelMap will contain between 2 and 50 digits ('0'-'9'), inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Johnny has recently constructed a cannon, and he wants to a hit a ground target that is distance units away. The cannon shoots bullets at velocity units per second. When a bullet is in the air, its flight follows the standard laws of physics. This means that if he shoots a bullet at angle alpha from the ground, it will travel a distance of The cannon can only be set at the angles given in the int[] angles (all angles are given in degrees). Johnny must pick the angle that will land the bullet as close as possible to the target. Return this closest possible distance between the landing point and the target as a double. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The returned value must be accurate to within a relative or absolute value of 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | velocity will be between 1 and 1000, inclusive. | ||||||||||||
| - | distance will be between 0 and 100000, inclusive. | ||||||||||||
| - | angles will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | Each element of angles will be between 0 and 90, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
In some forms of geometry, like the kind used in geographical longitude/latitude measurements, angles are measured in base-60. The base unit is the degree. One degree contains 60 minutes, and one minute contains 60 seconds. You will be given the measurement of an angle in degrees, minutes, and seconds. Return the given angle in radians. Note that n degrees is equal to n*PI/180 radians. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The return value must have an absolute or relative error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | degrees will be between 0 and 359, inclusive. | ||||||||||||
| - | minutes will be between 0 and 59, inclusive. | ||||||||||||
| - | seconds will be between 0 and 59, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
A triangle is "inscribed" in a circle if all 3 points of the triangle are on the edge of the circle. For this problem, our circle will be centered at the origin and have a radius of 5. Our goal is to find the largest triangle (by area) we can inscribe in this circle. Normally, this would be any equilateral triangle, but in this case we have the added restriction that each point of our triangle must be within one (or more) of the valid ranges of degrees. The degree ranges are given in thousandths of degrees in corresponding elements of angleFrom and angleTo. For each range, angleFrom will be less than or equal to angleTo and each will be between 0 and 360000. All ranges are inclusive; see the examples for clarification. Return the area of the largest inscribed triangle that can be made while following these restrictions. If no triangle can be made, return 0. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The ranges may overlap. | ||||||||||||
| - | Your return value must have an absolute or relative error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | angleFrom and angleTo will each contain between 1 and 30 elements, inclusive. | ||||||||||||
| - | angleFrom and angleTo will contain the same number of elements. | ||||||||||||
| - | Each element of angleFrom and angleTo will be between 0 and 360000, inclusive. | ||||||||||||
| - | Each element of angleFrom will be less than or equal to the corresponding element of angleTo. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | ||||||||||||||||||||||||
| A random walk in a directed graph starts at some node in the graph and then follows one of that node's outgoing edges uniformly at random. The process is then repeated from the next node and so on. If a graph consists of a single strongly connected component, then a random walk will eventually visit every node in the graph. In this problem, your program will make a random walk of a graph. However, you will only be able to observe the in and out degrees of the vertices that you visit. Your task is to make as short a random walk as possible such that you have visited every node in the graph. You should write two methods: init and walk. The init method will be called first with a single integer argument: the number of vertices in the graph. Subsequent calls will be made to the walk method and will give a sequences of in and out degree observations. Both of these methods should return an integer between 0 and one million, inclusive, indicating the number of steps your program wants to move at once. So, if you want to take 10 steps in the first iteration, your init method should return 10. Then, you will be given 10 degree observations in the next call to the walk method. You are allowed to observe at most 10 sequences of degrees (walk will be called at most 10 times). Each time it will be given a int[] with 2 elements per observations. Element 2*i and 2*i+1 will given the in and out degrees of the ith observation, respectively. If you ever return 0, it will be assumed that you are done and want to make no further observations. Scoring will be based on two factors: the number of nodes that you visit before quiting, and the total number of observations you make. In the best case, you will stop as soon as you hit the last unvisited node, in which case you will get 100 points. If you don't visit all the nodes, you will lose half your points for each unvisited nodes, so your score will be 100*0.5unvisited. If you visit all the nodes and make some additional observations, your score will be 100-(percent extra observations)/3 (with a minimum of 0). For example, if you visited all but 2 nodes, you would get 25 points. If you visisted the last node on observation 100, but you made a total of 130 observations, you would receive 90 points (having made 30% extra observations). Your total score will simply be the sum of your individual scores. The graphs will be generated via a very simple model. First, the number of nodes will be selected between 10 and 100, inclusive, with size K chosen with probability proportional to 1/K. Then, a probability, p is chosen between 0 and 10/K. For each potential edge (u,v) (where u does not equal v), that edge is added with probability p. If the generated graph has a single strongly connected component, it is kept, otherwise, p and all the edges are regenerated (the size is kept), and the process is repeated until a graph with a single strong component is generated. | ||||||||||||||||||||||||
Definition | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
Notes | ||||||||||||||||||||||||
| - | You will have a total of 20 seconds execution time (not 20 seconds per sequence). | |||||||||||||||||||||||
| - | The memory limit is 64 MB. | |||||||||||||||||||||||
| - | There are 100 test cases. | |||||||||||||||||||||||
| - | Graphs are given as adjacency lists. For instance, in example 0, there are edges from node 0 to nodes 1, 2 and 9. | |||||||||||||||||||||||
| - | The return from the 10th call to walk is ignored (treated as if it is 0). | |||||||||||||||||||||||
| - | The calls to walk form a single continuous random walk. In other words, concatenating all of the inputs to the walk methods gives a continuous walk. | |||||||||||||||||||||||
Examples | ||||||||||||||||||||||||
| 0) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 1) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 2) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 3) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 4) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 5) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 6) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 7) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 8) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 9) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| You are given the vertices of a convex polygon in clockwise order. As you traverse the boundary in the given order, your heading adjusts toward your right at each vertex by more than 0 but less than 180 degrees. As you
complete the circuit by going from the last vertex to the first vertex and then
heading toward the second vertex, your
total heading adjustment has been 360 degrees.
We want to increase the size of the given convex polygon by picking some of its vertices and moving them. We are not allowed to choose vertices that are adjacent to each other, and we are not allowed to move a chosen vertex a distance of more than 1. Of course the boundary segments between a moved vertex and its fixed adjacent vertices also move -- we require that moving boundary segments never intersect any other boundary segments. This guarantees that we will end up with a polygon (possibly not convex) that has a well-defined interior and exterior. Create a class PolyMove that contains a method addedArea that is given the sequence of vertices of a convex polygon in int[]s x and y. It returns the greatest increase in area that can be achieved by choosing and moving vertices. The coordinates of the i-th vertex are given by the i-th elements of x and y. There is a boundary segment between the last vertex and first vertex. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | A return value with either an absolute or relative error of less than 1.0E-9 is considered correct. | ||||||||||||
Constraints | |||||||||||||
| - | x and y will contain the same number of elements, a number between 3 and 50, inclusive. | ||||||||||||
| - | Each element of x and of y will be between -1000 and 1000, inclusive. | ||||||||||||
| - | The points corresponding to x and y will be distinct. | ||||||||||||
| - | The described polygon will be clockwise convex as specified above. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
A ball is moving diagonally on a rectangular board composed of unit squares in rows rows and columns columns. Each square is identified by its row and column number. The lowermost row is marked row 0 and the leftmost column is column 0. The ball is initially located in the middle of a starting square given by two integers, startrow and startcol, and is moving diagonally up-right at an angle of 45 degrees. Whenever it reaches a wall, it bounces off it at a right angle (an angle of 90 degrees) and continues moving. If the ball runs into a corner, it bounces back in the opposite direction from which it came..
A number of holes have been drilled in the board and the ball will fall in upon reaching a square with a hole. Given the board size, starting location and locations of holes, return the number of times the ball will bounce off a wall before falling into a hole, or -1 if the ball will continue bouncing indefinitely. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Bouncing back from a corner counts as only one bounce. | ||||||||||||
Constraints | |||||||||||||
| - | rows and columns will be between 1 and 1000000, inclusive. | ||||||||||||
| - | startrow will be between 0 and rows-1, inclusive. | ||||||||||||
| - | startcol will be between 0 and columns-1, inclusive. | ||||||||||||
| - | holes will contain between 0 and 50 elements, inclusive. | ||||||||||||
| - | Each element of holes will be formatted as "row column" (quotes for clarity), where row and column will be integers with no leading zeros representing a square inside the board. | ||||||||||||
| - | There will be no holes at the starting position of the ball. | ||||||||||||
| - | No two holes will occupy the same position on the board. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
| 7) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
We have a big digital wall clock, but while hanging it on the wall, we mounted it upside-down by mistake (i.e. the display was rotated 180 degrees). To make things worse, the clock has a complicated mechanism inside that makes it go slow when it is upside-down, needing secsPerMinute seconds to advance a minute instead of 60 seconds. Note that even at the moment we hang the clock on the wall, this is not necessarily set at the correct time. The clock itself only displays hours (from 00 to 23) and minutes (from 00 to 59), including any leading zeros. You are given a String currentTime in the form "HH:MM", representing the actual (correct) time at which the clock is mounted on the wall, and a String clockTime also in the form "HH:MM", representing the time the clock is displaying when it is mounted on the wall (the time that we would see if the clock was mounted normally, not upside-down). Assume in both times that the seconds part is 0, i.e., the time just changed to currentTime and the clock just advanced to clockTime. You are to compute the first time after the clock is mounted on the wall that the clock shows the correct time (i.e., the display as shown now that the clock is mounted upside-down represents the correct time) and return this as a String in the form "HH:MM", including any leading zeros. If the clock never shows the correct time, return an empty String. When the clock time is read upside-down, the digits 0, 1, 2, 5 and 8 are the same, 6 is shown as 9 and 9 is shown as 6. The digits 3, 4 and 7 do not show any meaningful digits when read upside-down. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | You may assume that when the clock display is updated to the next minute, this update takes zero time. | ||||||||||||
Constraints | |||||||||||||
| - | currentTime and clockTime will have exactly 5 characters each, in the form "HH:MM". "HH" will be an integer between 00 and 23, inclusive (including any leading zeros), "MM" will be an integer between 00 and 59, inclusive (including any leading zeros). | ||||||||||||
| - | secsPerMinute will be between 61 and 1000, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Little Timmy has a rectangular frame and several shapes cut out from cardboard. He tries to fit each of the shapes into the frame (one shape at a time). Sometimes the piece fits easily, sometimes it is clear that the shape is too big to fit... and sometimes Timmy just doesn't know. Then he always comes to ask you for help. You decided to write a program that will answer Timmy's questions. You will be given the width and height of the frame and a String[] shapes describing Tommy's shapes. Each of the shapes is either a circle or a rectangle. Each element of shapes is of the one of the following forms:
Your method is supposed to return a String[] results, where the i-th element of results is "YES" or "NO", depending on whether the i-th shape fits into the empty frame. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The shapes may be rotated arbitrarily. | ||||||||||||
| - | The shapes may touch the frame, and they may even have a common part of the boundary. | ||||||||||||
Constraints | |||||||||||||
| - | width and height are between 1 and 1000, inclusive. | ||||||||||||
| - | shapes contains between 1 and 50 elements, inclusive. | ||||||||||||
| - | Each element of shapes is of one of the following forms:
| ||||||||||||
| - | All numbers in shapes are integers between 1 and 1000, inclusive, with no leading zeroes. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Given a rectangular object and several boxes (in this problem, we ignore the height of the box, so a box only has two dimensions) of different sizes, you want to find the box with the smallest area which is large enough to contain the object. When putting the object in the box, it's sides must be parallel with the sides of the box. Thus, you may only rotate the object 0, 90, 180 or 270 degrees (although for obvious reasons you only need to consider rotating with 0 and 90 degrees). Create a class ObjectPacking which contains the method smallBox which takes an int objWidth, an int objLength (the width and length of the object), a int[] boxWidth, a int[] boxLength (the width and length of the boxes) and returns an int, the area of the smallest box that can fit the object. Element i in boxWidth and boxLength correspond to box i. If no box is big enough to contain the object, return -1. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | There doesn't have to be any gap between the sides of an object and the sides of the box. Thus, an object with width 5 and length 7 will fit in a box with width 7 and length 5. | ||||||||||||
| - | Return -1 if there is no box big enough to contain the object (see example 1). | ||||||||||||
Constraints | |||||||||||||
| - | objWidth will be between 1 and 1000, inclusive. | ||||||||||||
| - | objLength will be between 1 and 1000, inclusive. | ||||||||||||
| - | boxWidth will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | boxLength will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | boxWidth will contain the same number of elements as boxLength. | ||||||||||||
| - | Each element in boxWidth will be between 1 and 1000, inclusive. | ||||||||||||
| - | Each element in boxLength will be between 1 and 1000, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| In Euclidean Geometry, triangles can be categorized into one of three types
based on their angle measures. A triangle is acute if all three angles are
less than 90 degrees. A triangle is obtuse if one angle is greater than 90
degrees. Lastly, a triangle with one angle at exactly 90 degrees is a right
triangle.
It could also be the case that three positive integers can not possibly form the side-lengths of a triangle. This happens when the length of one side is equal to or larger than the sum of the lengths of the other two sides, because it would not be possible to connect the end points of the three sides in such a way that a triangle was formed. Write a method that takes as input three positive integer side-lengths of a triangle. Return "IMPOSSIBLE" if a triangle cannot be formed. Return "ACUTE" if the triangle is acute, "OBTUSE" if the triangle is obtuse, and "RIGHT" if the triangle is right. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | For a triangle with side-lengths x, y, and z and x <= y <= z. * The triangle is right if x*x + y*y = z*z. * The triangle is obtuse if x*x + y*y < z*z. * The triangle is acute if x*x + y*y > z*z. * It is impossible to have x + y <= z. | ||||||||||||
Constraints | |||||||||||||
| - | a, b, and c are between 1 and 10,000, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
You have a rectangular sheet of paper, from which you wish to cut a pattern. The pattern is a figure composed of unit squares. You wish to cut out as many instances of the pattern as possible from the sheet of paper. The pattern may be cut out exactly as is, or may be rotated 90 or 180 degrees (in either direction). You are given ints height and width, describing the size of the sheet of paper, and a String[] pattern that defines the pattern you want to cut out. pattern is composed of 'X' characters and period ('.') characters, where 'X' is part of the pattern, and '.' is not. The following respresents the 7 valid patterns with 4 'X's (ignoring rotations of the same pattern):
{"XXXX"}
{"XXX",
"X.."}
{"XXX",
"..X"}
{"XXX",
".X."}
{"XX.",
".XX"}
{"X.",
"XX",
".X"}
{"XX",
"XX"}
So, for the T-shaped pattern, from a 4 x 5 sheet of paper, you could cut out the pattern four times. One way would be like this: A.BBB AA.BC AD.CC DDD.C You are to return an int indicating the maximum number of times the given pattern can be cut from the sheet of paper. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | height and width will be between 1 and 6, inclusive. | ||||||||||||
| - | pattern will contain between 1 and 6 elements, inclusive. | ||||||||||||
| - | Each element of pattern will contain between 1 and 6 characters, inclusive. | ||||||||||||
| - | Each element of pattern will contain the same number of characters. | ||||||||||||
| - | Each character of each element of pattern will be 'X' or '.'. | ||||||||||||
| - | The first character of the first element of pattern will be 'X'. | ||||||||||||
| - | Each block of the pattern will be connected (horizontally or vertically) to the rest of the pattern. | ||||||||||||
| - | The pattern will not contain any empty rows or columns (it will not be "padded"). | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
We've all seen hinged doors before, perhaps in the entrance to a kitchen. Have a look at the figure below to make things clear. This particular hinged door works as follows: From "rest position" (the solid line below), the door is pushed at one end, and it swings out through an angle (in the image, this corresponds to "1st swing"). Then, when the door is released, it swings to the other side (this is shown in the image as "2nd swing"), but this time, the angle through which it swings is reduced to a known fraction of the previous angle. Then, the direction is reversed again and once more, the angle reduced by the same fraction. Once the angle drops to 5.0 degrees or below, the door doesn't swing any more, but rather, it returns to "rest position".
Create a class HingedDoor which contains a method numSwings. The method takes an int initialAngle and an int reduction as input and returns an int corresponding to the number of times the door will swing before coming to rest when initially displaced by initialAngle. Remember that each time the door will swing through an angle reduction times less than the angle it swung through the previous time. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | initialAngle will be between 0 and 90, inclusive. | ||||||||||||
| - | reduction will be between 2 and 10, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
You are watching a car race. Each car starts a different point on the x-axis, travels at the same speed, and starts at the same time. However, each car is travelling along a different road (which extends to infinity in one direction, and is stopped by the x-axis in the other direction), and each road has its own direction specified by an angle between 1 and 179, inclusive. An angle of 90 indicates that the road heads directly in the positive y direction, while an angle of 1 indicates that the road heads just a little bit north of the positive x direction. Note that cars never head in the negative y direction.![]() Sometimes, two or more roads intersect at some point. When this happens, the car that reaches the intersection first is able to block the intersection so that no other cars can pass through it. If two cars reach an intersection at the same time, the one with the lower index passes, while the other one is blocked. ![]() In this picture, the cars following the red paths make it through all of the intersections, while the cars on the gray paths are blocked. You will be given a int[] angles, where the ith element of angles is the angle between the x-axis and the road that the ith car drives on, in degrees. The order of the elements of angles corresponds to the order of the cars along the x-axis (no two cars start at the exact same location), with the first element of angles corresponding to the car with the leftmost starting position on the x-axis. Your method should return a int[] containing the 0-based indices of all the cars that will pass all of the intersections along their roads. Your return should be sorted in ascending order. Note that the exact locations of the cars along the x-axis do not matter. All that matters is their order, and the directions in which they head. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | angles will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | Each elemtent of angles will be between 1 and 179, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
You will be given a String[] maze containing blank spots ('.' characters), walls ('X' characters), your character (a single 'Y' character), and the destination (a single 'D' character). You have implemented the following naive maze traversal strategy:
| |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | If your character is at (element E, character C) of maze, and the current direction is Down-Right, then taking one step would leave you at (element E+1, character C+1) of maze. The other diagonal directions are treated analogously. | ||||||||||||
| - | The following sequence of directions are formed by consecutively turning 45 degrees clockwise: Right, Down-Right, Down, Down-Left, Left, Up-Left, Up, Up-Right, Right. | ||||||||||||
Constraints | |||||||||||||
| - | maze will contain between 1 and 50 elements inclusive. | ||||||||||||
| - | Each element of maze will contain between 1 and 50 characters inclusive. | ||||||||||||
| - | Each element of maze will contain the same number of characters. | ||||||||||||
| - | Each character in maze will be (quotes for clarity) '.', 'X', 'Y', or 'D'. | ||||||||||||
| - | maze will contain exactly one 'Y' and one 'D'. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Soma is a three dimensional puzzle invented by Piet Hein. You have seven pieces which are formed by joining cubes at their faces. (They are all of the non-convex shapes that can be so formed with four or fewer cubes). Six of the pieces are formed from four cubes and one is formed by three cubes. There are 27 cubes total. The pieces can be described by the following arrays which show how high cubes are stacked in each grid cell, and are also shown in the picture below. 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 1 1 0 1 1 0 2 2 0 1 2 1 0 1 1 1 1 0 1
The pieces can be translated and rotated into any orientation, to build larger shapes, but can not be reflected (as in a mirror) or disassembled. Pieces may touch, but not intersect. Each piece is used exactly once in a solution. Given pattern (a shape composed of 27 cubes, not necessarily connected), try to arrange the seven soma pieces into the same shape as pattern. In other words, you are constructing pattern using the seven pieces. Return the number of distinct solutions for pattern.
What is meant by "distinct": The pattern will be specified in a String[] similar to the arrays showing the individual pieces above. Each character indicates how many cubes are stacked at that location, starting from a common plane at a height of zero. For example:
{"333",
"333",
"333"}
specifies a 3x3x3 cube which is possible to construct with the seven soma pieces in 11520 distinct (as defined above) ways, so return 11520. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | If no rotational symmetries are involved, there are 24 possible orthogonal orientations resulting from rotations in three dimensions. Visualize the 3x2 "L" shaped piece (which has no rotational symmetry). The top (long end) of the "L" can point in six directions x,y,z,-x,-y,-z. For each of those, the short leg of the "L" can point in one of four directions. 6 x 4 = 24 | ||||||||||||
| - | Each of the other six pieces does have some rotational symmetry, and thus fewer possible distinct orientations. | ||||||||||||
| - | The rotation of a point about a line passing through the origin can be calculated using a single, vector by matrix, multiplication: [x y z]*M=[rx ry rz] where M is a 3 by 3 matrix, [x y z] is the original point and [rx ry rz] is the rotated point. | ||||||||||||
| - | Vector by matrix multiplication is defined as: for(i) { r[i]=0 ; for(j) { r[i]+=p[j]*M[j][i] } } where p is the original point and r is the rotated point. | ||||||||||||
| - | The matrix for 90 degree rotation about the x axis is: {{1,0,0},{0,0,1},{0,-1,0}} | ||||||||||||
| - | The matrix for 90 degree rotation about the y axis is: {{0,0,-1},{0,1,0},{1,0,0}} | ||||||||||||
| - | The matrix for 90 degree rotation about the z axis is: {{0,1,0},{-1,0,0},{0,0,1}} | ||||||||||||
| - | The easiest way to generate all possible orthogonal orientations is to rotate about the x axis (0,90,180 or 270 degrees), then about the y axis (0,90,180 or 270 degrees) then about the z axis (0,90,180,270 degrees). That is 64 combinations of rotations (4x4x4). Try all 64 and throw away those that produce duplicate results. | ||||||||||||
| - | Sequences of rotations in three dimensions are non-commutative. The order in which you apply the rotations matters. | ||||||||||||
| - | There are 240 fundamental patterns to form the cube, proven by the great mathematician, Prof. John H. Conway. 240 x 24 rotations x 2 (for mirror reflection) = 11520. There are 96 ways to rotate individual pieces in each of the 11520 "distinct" ways. 11520 x 96 = 1105920 which is the "over a million ways to build a cube" number the manufacturer uses. | ||||||||||||
Constraints | |||||||||||||
| - | pattern will contain between 2 and 27 elements, inclusive. | ||||||||||||
| - | Each element of pattern will consist of between 2 and 27 characters, inclusive. | ||||||||||||
| - | Each element of pattern will have the same number of characters. | ||||||||||||
| - | Each character in each element of pattern will be a digit between '0' and '9' inclusive. | ||||||||||||
| - | The sum of all the digits in pattern will be exactly equal to 27. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
| 7) | |||||||||||||
| |||||||||||||
| 8) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Warning: This problem statement contains images that may not be visible to plugin users. For best results, use the standard Arena editor. Raccoons dug up your lawn during the spring, but now they've agreed to resurface it for a modest fee. They come equipped with a turf roller and a truckload of rectangular turf strips of fixed dimensions. We say that "length" is the measure of a turf strip's longer edges, while "breadth" is the measure of its shorter edges. Your lawn is also rectangular: from a bird's-eye view, what we call "width" is the distance from its left border to its right border, and "height" is the distance from bottom to top. For aesthetic reasons, you demand that the turf be laid at a certain angle. This angle is between 0 and 90 degrees, inclusive, and is measured counterclockwise from the bottom border of your lawn. In other words, the raccoons will ensure that the longer edges of every turf strip are inclined at precisely this angle relative to the horizontal axis. It may well happen that a single turf strip laid at the desired angle is not long enough to span your lawn. In such cases, the raccoons lay several turf strips end to end, precisely aligning the shorter edges of subsequent strips. At no time will turf strips overlap. Any scraps of turf that overhang the lawn's borders are immediately trimmed off and discarded. Once the raccoons have completed their labors, the entirety of your lawn will be covered with fresh turf. You are given five integers that respectively state: the width of your lawn; the height of your lawn; the angle at which turf is to be laid; the length of each turf strip; and the breadth of each turf strip. Calculate the minimum number of turf strips that the raccoons must use in the course of resurfacing your lawn. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Turf strips must always be laid lengthwise, as in the illustrations below. Breadthwise orientation is not permitted. | ||||||||||||
| - | Each turf strip must be laid at the specified angle, even if a different angle would allow the whole lawn to be covered with a single piece. | ||||||||||||
Constraints | |||||||||||||
| - | lawnWidth is between 1 and 100, inclusive | ||||||||||||
| - | lawnHeight is between 1 and 100, inclusive | ||||||||||||
| - | stripAngle is between 0 and 90, inclusive | ||||||||||||
| - | stripLength is between 1 and 100, inclusive | ||||||||||||
| - | stripBreadth is between 1 and 100, inclusive | ||||||||||||
| - | stripBreadth is less than or equal to stripLength | ||||||||||||
| - | If the angle is not 0 or 90, then the input is such that the final result will not be affected by small precision errors in your intermediate calculations. Specifically, the result would remain the same if both the length and width of the lawn were greater by 0.1 or less by 0.1 than they are in the input. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
In a robust computer system, one of the most important pieces is the cooling. Without proper cooling, processors can heat up to over 400 degrees C. The reliability of a system can be measured by determining how many fans can fail without risking the system processor. Each fan can be assigned a value indicating how much capacity it has to cool the system, and we can define a minimum cooling capacity, which the sum of the fan capacities must exceed to properly cool the system. We define a Failure Set as a set of fans which are not necessary to cool the system. In other words, if the fans in a Failure Set break, the system can still be properly cooled by the remaining fans. The count of a Failure Set is the number of fans in the set. To measure the reliability, we will define two values, the Maximum Failure Set (MFS) and the Maximum Failure Count (MFC). A MFS is a Failure Set of fans with the largest count possible. A set of fans may have more than one MFS (see below). A Failure Set is an MFS if and only if there are no Failure Sets with a higher count. The MFC is the largest value such that all fan sets with count <= MFC are Failure Sets. In other words, any set of fans of size MFC or less can fail, and the system will still be properly cooled by the remaining fans. Consider the fan set with capacities 1, 2, 3, and a cooling requirement of 2. Two MFSs with a count of 2 exist: fans 1 and 3, or fans 1 and 2. However, the MFC is not 2 because fans 2 and 3 is not a Failure set (fan 1 could not cool the system properly by itself). Thus, the MFC is 1, because if any single fan fails, the system can still be cooled. You will be given a int[] capacities, which designates how many units of cooling each fan provides, and an int minCooling, which designates the minimum units of cooling required to cool the system. Your method should return a int[], where the first value should be the number of fans in the Maximum Failure Set (MFS), and the second value should be the Maximum Failure Count (MFC). | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | capacities has between 1 and 50 elements, inclusive. | ||||||||||||
| - | each element of capacities is between 1 and 1000, inclusive. | ||||||||||||
| - | minCooling is between 1 and 50000, inclusive. | ||||||||||||
| - | The sum of all elements in capacities will be greater than or equal to minCooling. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
| Given a rectangular grid of squares, how many different convex polygons can be drawn
whose vertices are all points on the grid and whose sides are either
horizontal, vertical or (45 degree) diagonal?
We define the width of the given rectangular grid to be the number of intersection points along one if its horizontals (including both the leftmost and rightmost points). Similarly the height of the grid is the number of intersection points along one of its verticals. We want to count the number of different "grid polygons" that could be formed. A grid polygon is a polygon with the following properties:
Two grid polygons should be counted as different if their boundaries are not identical. If they are the same shape but in different locations they are different. But placing an extra vertex in the middle of an edge does not change the boundary so it does not create a new grid polygon. Create a class ConvexPoly that contains a method count that is given two ints w, the grid width, and h, the grid height, and that returns the number of grid polygons that could be formed. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | w will be between 2 and 100 inclusive | ||||||||||||
| - | h will be between 2 and 100 inclusive | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Combination locks are convenient, because of their design. A combination lock consists of a small wheel to input the combination, and a latch to actually lock things together. The wheel contains consecutive numbers equally spaced around its edge, starting from zero and increasing clockwise. The outer casing of the lock has a small notch. To open the lock, you must rotate the wheel and align the numbers on the wheel with the notch in a specific order. TopLock, a small company manufacturing combination locks, has recently decided to change its lock setup to give more security than the competitors. Many typical combination locks have a set of three numbers which you must input in order. TopLock locks will have a variable combination length which will be no less than three. In addition, they will be changing the number of numbers on the wheel, which will be between 10 and 100, inclusive. To open a lock, you must follow the algorithm outlined below:
It is guaranteed that no two adjacent numbers in combo will be the same, so as to avoid ambiguity in step 3. Also, the starting position of the lock, start, will not be the same as the first number in combo. Given a int[] combo, indicating the combination of the lock, an int size, the number of numbers on the wheel, and an int start, indicating the number that the notch starts off pointing at, your method should return a double indicating the total number of degrees turned to open the lock. For example, if combo = {10,20,30}, size = 40, and start = 6, you would first rotate the wheel three times counterclockwise and then 4 units to the 10, for a total of 3 * 360 + 4 * (360 / 40) = 1116 degrees, and then you would rotate twice clockwise and 30 units to the 20, and then once counterclockwise and 10 units to the 30. Your method would in this case return 1116 + 990 + 450 = 2556. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The numbers on the combination wheel start at 0 and go to (size - 1), increasing clockwise. | ||||||||||||
| - | Double return values must be correct to within an absolute or relative difference of 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | combo will have between 3 and 50 elements, inclusive. | ||||||||||||
| - | Each element of combo will be between 0 and (size - 1), inclusive, and no two consecutive elements will be the same. | ||||||||||||
| - | size will be between 10 and 100, inclusive. | ||||||||||||
| - | start will be between 0 and (size - 1), inclusive, and will not be the same as the first element in combo (i.e., the one with index 0) | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
Graphs are relatively common data structures in computer science. To visualize a graph, we often display it as a bitmap like this one:
However, an image is not very easy to work with for most purposes. It is usually much easier to perform common tasks (like finding a shortest path) if the graph is represented as a set of nodes and edges. In this problem, you will be given a graph as a bitmap, and are to convert it to a set of nodes and edges. You have some information about the bitmap to make this task easier. First, you know that all nodes in the graph are represented by a single pixel of a certain color, which will be represented by an 'N' in the input. Furthermore, each edge will be a single color, represented by an 'E' in the input. The rest of the pixels will be represented by '.'s. After examining the images, you've come up with the following sketch for an algorithm to find and follow edges:
| |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Only list individual loops (edges from a node to itself) once. See example 4. | ||||||||||||
Constraints | |||||||||||||
| - | bitmap will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | Each element of bitmap will contain the same number of characters. | ||||||||||||
| - | Each element of bitmap will contain between 1 and 50 characters, inclusive. | ||||||||||||
| - | Each character of bitmap will be an 'E', an 'N', or a '.'. | ||||||||||||
| - | If you follow each edge as described in the problem statement, each edge will terminate at a node. | ||||||||||||
| - | There will not be two adjacent 'N's. | ||||||||||||
| - | All of the edges will be traversed in the same manner in both directions. In other words, if there is an edge from node i to node j, there will also be an edge from node j to node i which uses all of the same pixels. | ||||||||||||
| - | There will be no ambiguity as to which way to go when a 45 turn must be made. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
|
A government agency plans to establish a network of satellites to monitor rocket launches worldwide. You have been asked to develop a simulation that will help assess the coverage of a given satellite configuration. Given a collection of satellite positions and a collection of launch positions, you are to determine which rockets can be accurately detected before they leave boost phase. For the purpose of this simulation, the Earth is a sphere with a diameter of 12800 kilometers. When a rocket is launched, it flies straight up from the surface. All satellites operate at an altitude between 200 and 1200 kilometers, inclusive, and hold their position for the duration of the simulation. A rocket can be accurately detected only if it is visible to at least three satellites when its boosters are depleted at the altitude of 400 kilometers. In order to preclude floating-point error, the simulation will not include cases in which the line between a satellite and a rocket at the 400-kilometer altitude passes within one millimeter of the Earth. The locations of the rocket launches are specified by a String[], rockets, each element of which contains exactly 19 characters. The first nine characters encode a fixed-point number in the following manner: the first character is either plus ('+') or minus ('-'); the next four characters are the integer part of the number, padded with zeros as necessary; the next character is the decimal point ('.'); the final three characters are the zero-padded fractional part of the number. This number gives the latitude of the rocket launch. The tenth character of each element in rockets is a space, and the last nine characters give the longitude of the corresponding rocket in the same fixed-point format. Latitudes range between -90.0 and 90.0 degrees, inclusive, while longitudes range between -180.0 and 180.0 degrees, inclusive. The equator is at latitude zero; the North Pole, at 90 degrees; the South Pole, at -90 degrees. Longitude zero runs through the Greenwich Royal Observatory in London. Positive longitudes are measured to the east of Greenwich, negative ones to the west. Longitudes 180 and -180, which are one and the same, lie on exactly the opposite end of the globe from longitude zero. If a rocket were launched from the Eiffel Tower, for example, its location would be given as "+0048.867 +0002.267". The locations of the satellites are described by another String[], satellites, each element of which contains exactly 29 characters. The first 19 characters encode the latitude and longitude, just as for rocket launches, of the terrestrial point closest to the satellite. The 20th character is a space, and the last nine characters give the satellite's distance in kilometers from the Earth's surface, again using the same fixed-point format. For example, a satellite flying at an altitude of 550 kilometers over Mount Everest would have the location "+0027.988 +0086.925 +0550.000". You are to return a int[] containing the zero-based indices, sorted by ascending value, of those rockets that can be detected at an altitude of 400 kilometers by at least three satellites. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | This simulation ignores collisions. Several satellites or rockets, or both, may occupy the same point at the same time. | ||||||||||||
Constraints | |||||||||||||
| - | rockets contains between 1 and 50 elements, inclusive | ||||||||||||
| - | each element of rockets conforms to the format described above | ||||||||||||
| - | satellites contains between 1 and 50 elements, inclusive | ||||||||||||
| - | each element of satellites conforms to the format described above | ||||||||||||
| - | the input is such that no line of sight between a satellite and a rocket at the 400-kilometer altitude passes within one millimeter of the Earth | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
A robotic courier needs to deliver a package through a minefield, following a safe path discovered by a robotic scout. The scout's path is not necessarily as efficient as it could be. For example, it might loop back on itself. The courier need not follow the path exactly, but can take shortcuts when it can do so safely. Each robot can make only three kinds of moves, each represented by a single letter: it can go forward 1 meter ('F'), pivot right 60 degrees ('R'), or pivot left 60 degrees ('L'). Notice that the locations on which a robot can begin or end a move form a hexagonal grid. The scout and courier begin in the same location, facing in the same direction. The courier's goal is to reach the last location visited by the scout as quickly as possible. To travel safely, the courier must always stay in the wheel tracks of the scout. That is, any forward movement made by the courier must be along a path segment traveled by the scout. Pivoting left or right is always safe. Note that the courier is permitted to follow a path segment in either the same or the opposite direction as the scout. Similarly, the courier may be facing in any direction when it reaches its final destination--it need not end up facing in same direction as the scout. The courier requires 3 seconds to pivot left or right 60 degrees, and 4 seconds to move forward one meter. However, because of acceleration effects, the courier can move faster when it makes several consecutive forward moves. The first and last moves in any such sequence take 4 seconds each, but intermediate moves in the sequence take 2 seconds each. For example, it would take the courier 20 seconds to travel 8 meters in a straight line: 4 seconds for the first meter, 4 seconds for the last meter, and 12 seconds for the six meters in between. For example, suppose the scout follows the path "FRRFLLFLLFRRFLF" (all quotes for clarity only). Altogether, it visits six locations, which can be drawn as
_
/6\_
\_/5\_
\_/4\
/2\_/
\_/3\
/1\_/
\_/
It begins in hexagon 1, facing upward, and travels in order to hexagons 2, 3, and 4. It then returns to hexagon 2 before continuing on to hexagons 5 and 6. The courier could deliver the package in a minimum of 15 seconds, using the path "FFLF" which visits hexagons 1, 2, 5, and 6.
The scout's path will be given as a String[] path, rather than as a single String. For example, the scout's path above might have been given as {"FRRFLLFLL", "FRRFLF"}. Note that there is no significance to where the breaks fall between strings in path; it is best to think of all the strings being concatenated together. Given the path, you must calculate the minimum time needed for the courier to deliver its package. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | path contains between 1 and 10 elements, inclusive. | ||||||||||||
| - | Each element of path contains between 1 and 50 characters, inclusive. | ||||||||||||
| - | Each element of path contains only the characters 'F', 'L', and 'R'. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
A convex polygon is a set of n vertices that are joined by n edges, such that no two edges intersect and all angles are less than 180 degrees. We can represent a polygon by listing all the vertices, starting at one vertex and following the edges until that vertex is reached again. Thus, element 0 in the array represents the first vertex. The first vertex is connected to the second vertex (element 1), the second vertex is connected to the third vertex (element 2) and so on. The last element represents the last vertex, which is connected to the first vertex. Given the vertices of a polygon, where the x-coordinate of vertex i is element i of int[] x and its y-coordinate is element i of int[] y, return its exact area. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | As long as your return has relative or absolute error less than 1e-9, it will be judged correct. | ||||||||||||
Constraints | |||||||||||||
| - | x and y will have the same number of elements. | ||||||||||||
| - | x will have between 3 and 50 elements inclusive. | ||||||||||||
| - | y will have between 3 and 50 elements inclusive. | ||||||||||||
| - | each element in x will be between -10000 and 10000 inclusive. | ||||||||||||
| - | each element in y will be between -10000 and 10000 inclusive. | ||||||||||||
| - | the represented polygon will NOT intersect itself. | ||||||||||||
| - | the represented polygon will NOT have any angles equal to or greater than 180 degrees. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
A hall of mirrors is a large room with many mirrors throughout it. When you look at one of these mirrors, often you end up seeing an object that is far away and has been reflected off many mirrors. To aid in the design of halls of mirrors, you are to write a class Mirrors with a method seen, which will tell you what object is seen, given a particular configuration of mirrors and objects, and the location and direction being looked. Your method will take a String[], mirrors, another String[], objects, and a int[], start. Each element of mirrors will be formatted as "<x1> <y1> <x2> <y2>", representing a mirror that starts at point (x1,y1) and ends at point (x2,y2). All mirrors are double sided. objects, will repesent all of the objects that are in the hall of mirrors and might be seen. Each element of objects will be formatted as "<name> <x> <y>", representing a circular object named <name>, centered at point (x,y) and with radius 1. Finally, start will represent the location and direction that a person is looking from. The first element will be the x coordinate, the second element will be the y coordinate, and the third element will be the heading that they are looking in. The heading will be in the range 0 to 359, representing the number of degrees in a counter-clockwise direction, starting from straight right (positive x), that the person is looking. Thus a heading of 0 means the person is looking in the positive x direction, a heading of 90 indicates the positive y direction, and a heading of 45 indicates that the person is looking half way between the positive x and positive y directions. Your method must determine what is seen when a person stands at the given coordinates and looks in the given direction. If the person sees himself, return "me". If the person doesn't see any object or himself, return "space". Otherwise return the name of the object the person sees. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | All mirrors are double sided, and should be treated as line segments. | ||||||||||||
| - | All objects, and the person, are perfect circles and have a radius of 1. | ||||||||||||
| - | A mirror reflects light such that the angle formed between the mirror and the incoming light is the same as the angle formed between the mirror and the outgoing light. Thus the angle between the incoming and outgoing light is 180-2*(angle between mirror and light). | ||||||||||||
| - | If you look along a mirror, the mirror has no effect. (see examples). | ||||||||||||
Constraints | |||||||||||||
| - | Each element of mirrors will be formatted exactly as "<x1> <y1> <x2> <y2>", with no extra spaces. | ||||||||||||
| - | Each element of objects will be formatted exactly as "<name> <x> <y>", with no extra spaces or leading 0's. | ||||||||||||
| - | mirrors will contain between 0 and 50 elements, inclusive. | ||||||||||||
| - | objects will contain between 0 and 50 elements, inclusive. | ||||||||||||
| - | start will contain exactly three elements, the first two representing x and y, respectively, and the third representing the heading the person is looking in. | ||||||||||||
| - | All coordinates will be integers in the range 0 to 1000, inclusive. | ||||||||||||
| - | The heading (3rd element of start) will be in the range 0 to 359, inclusive. | ||||||||||||
| - | No objects or mirrors will overlap other objects, mirrors, or the person (this includes touching at one point). | ||||||||||||
| - | No element of mirrors will represent a point. (x1==x2 and y1==y2) | ||||||||||||
| - | Each object will have a unique <name> other than "me" or "space". | ||||||||||||
| - | Each <name> will contain only lowercase characters. | ||||||||||||
| - | To avoid cumulative rounding errors, the object (or "me" or "space") seen will be seen in 50 mirrors or less. | ||||||||||||
| - | To avoid rounding errors, the object seen will be seen definatively. This means that no objects will be barely seen, or almost seen, and there will never be any question about which mirror is seen. This is ensured by checking that the path to the object seen does not pass within 0.001 of any other object, mirror, or the person. | ||||||||||||
| - | Each element of mirrors, and objects will contain between 1 and 50 characters, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
A traveling salesman has recently decided to go international and sell his wares around the globe. He has done in depth research and has come up with a list of cities which he thinks will provide the best market for his goods. In planning his trip, the salesman wants to minimize the total distance he has to travel because he does not particularly like traveling (which is unfortunate for him, as he is a traveling salesman) and furthermore, he figures the less distance he has to travel, the cheaper his trip will be. However, this salesman is not particularily good at math, and so you must write a computer program to help him find his way in the least distance. You will be given a set of cities defined by their longitudes and latitudes. In addition, you will be given the radius of the planet that this traveling salesman resides on. Assume that there are direct flights, both ways, between every pair of cities that the salesman wants to visit, and that the flights follow the shortest path possible (over the surface of the planet). In addition, the first element of the input String[] will be the city in which the salesman lives, and thus his trip must start and end at this city. Each city is defined by two numbers, a latitude and a longitude. The latitude is the number of degrees above the equator, with 90 being the north pole, and -90 being the south pole. The longitude is the number of degrees east or west of some arbitrary, predefined point. Thus, 90 degrees east is one quarter of the way around the globe in the eastern direction. If the result is not an integer, round it to the nearest integer (.5 rounds up) | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Assume the planet is a perfect sphere. | ||||||||||||
| - | To find the cartesion coordinates of a city, assuming the center of the planet is at (0,0,0), use the following formulas: x = r*cos(latitude)*cos(longitude) y = r*cos(latitude)*sin(longitude) z = r*sin(latitude) | ||||||||||||
Constraints | |||||||||||||
| - | cities contains between 2 and 9 elements, inclusive. | ||||||||||||
| - | Each element of cities represents a unique point on the globe. | ||||||||||||
| - | Each element of cities is formatted as "<latitude> <longitude>" where <latitude> is an integer in the range -90 to 90, inclusive, and <longitude> is an integer in the range -180 to 180, inclusive. | ||||||||||||
| - | radius is an integer between 1 and 1,000, inclusive. | ||||||||||||
| - | to avoid rounding errors, the shortest path, prior to rounding, will not be within 0.001 of <x>+0.5 for any integer <x>. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Problem Statement | |||||||||||||
|
I am considering buying a big new riding mower,
but I need to figure out how much hand trimming I will need to do. My lawn is a
square n x n grid of cells. Each cell is either grass, or it is a bush. It
is not possible to drive the mower over a bush.
The new mower occupies two adjacent cells. As it moves, the back end goes over the same cell that the front end previously occupied, and the front end can be steered either to the next cell in the direction the mower is headed, or to one that is 45 degrees to the left or right.The following diagrams give examples showing the possible cells (1, 2, or 3) that the front of the mower could be steered to given the location of the front(F) and back(B). - 1 2 - - 1 - F 3 B F 2 B - - - - 3 I will build a shed for the mower which will occupy two cells that are adjacent (either diagonally or orthogonally). The shed is really just a roof over a concrete floor, so it is open on all sides and the mower can freely pass through the shed going any direction. I am willing to destroy bushes to make room for the shed. Each time I mow I must return the mower to the shed facing the same way as before I started mowing. I don't mind going over the same places more than once, but every cell containing grass that I can't mow will have to be trimmed by hand. Create a class LawnMower that contains the method trimNeeded that takes the width of my lawn, n, and int[]s row and col giving the locations of my bushes, and returns the number of cells of grass that I will have to trim by hand (with my shed built in the best location). An element of row and the corresponding element of col give the location of a bush. A bush may be listed more than once -- the repetitions can be ignored. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | n is between 2 and 12 inclusive. | ||||||||||||
| - | row contains between 1 and 50 elements inclusive. | ||||||||||||
| - | col contains the same number of elements as does row. | ||||||||||||
| - | Each element of row is between 0 and n-1 inclusive. | ||||||||||||
| - | Each element of col is between 0 and n-1 inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.