Professor Math is working on a secret project and is facing a challenge where a list of numbers need to be encoded into a single number in the most efficient manner. After much research, Professor Math finds a 3 step process that can best encode the numbers:
The professor has shared an example and its explanation below. Given a list of numbers, can you help the professor build an efficient function to compute the final encoded number?
The first line of the input gives the number of test cases, T. This is followed by T test cases where each test case is defined by 2 lines:
For each test case, output one line containing
Case #x: y
,
where x
is the test case number (starting from 1) and
y
is the final encoded number.
Since the output can be a really big number, we only ask you to output the remainder of dividing the result by the prime 109 + 7 (1000000007).
1 ≤ T ≤ 25.
Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ Ki ≤ 10000, for all i.
Ki ≤ Ki+1, for all i < N - 1.
1 ≤ N ≤ 10.
1 ≤ N ≤ 10000.
1 4 3 6 7 9
Case #1: 44
Explanation for the sample input
There are N weighted points in a plane. Point i is at (Xi, Yi) and has weight Wi.
In this problem, we need to find a special center of these points. The center is a point (X, Y) such that the sum of max(|X-Xi|, |Y-Yi|)*Wi is minimum.
The input starts with one line containing exactly one integer T, which is the number of test cases. T test cases follow.
Each test case begins with one line containing one integer N. N lines follow. Each line contains three space-separated real numbers Xi, Yi, and Wi. Xi, Yi and Wi have exactly 2 digits after the decimal point.
For each test case, output one line containing Case #x: y
, where x
is
the test case number (starting from 1) and y
is the sum of max(|X-Xi|,
|Y-Yi|)*Wi for center (X, Y).
y
will be considered correct if it is within an absolute or relative error of 10-6 of the correct answer.
See the FAQ for an explanation of what that means, and what formats of real numbers we accept.
3 2 0.00 0.00 1.00 1.00 0.00 1.00 4 1.00 1.00 1.00 1.00 -1.00 1.00 -1.00 1.00 1.00 -1.00 -1.00 1.00 2 0.00 0.00 1.00 1.00 0.00 2.00
Case #1: 1.0 Case #2: 4.0 Case #3: 1.0
You are given a rectangular grid with N rows and M columns. Each cell of this grid is painted with one of two colors: green and white. Your task is to find the number of green cells in the largest Christmas tree in this grid.
To define a Christmas tree, first we define a good triangle as follows:
A good triangle with top point at row R, column C and height h is an isoceles triangle consisting entirely of green cells and pointing upward. Formally, this means that: The cell (R, C) is green, and for each i from 0 to h-1 inclusive, the cells in row R+i from column C-i to column C+i are all green.
For example:
..#..
is a good triangle with height 3. The # cells are green and the . cells are white. Note that there is a green cell that is not part of the good triangle, even though it touches the good triangle.
.####
#####
..#..
is NOT a good triangle, because the 5th cell in the 3rd row is white. However, there are good triangles with height 2 present.
.###.
####.
...#.
is NOT a good triangle. However, there are good triangles with height 2 present.
.###.
#####.
A K-Christmas tree is defined as follows:
For example, if K = 2:
...#...
is a valid 2-Christmas tree. Note that the height of the 2 good triangles can be different.
..###..
.#####.
#######
..#....
.###...
#####..
..#..
is also a valid 2-Christmas tree. Note that a good triangle can be of height 1 and have only one green cell.
.###.
.#...
...#...
is NOT a valid Christmas tree, because the 2nd triangle must starts from the 4-th row.
..###..
.#####.
.......
..#....
.###...
#####..
...#.
is NOT a valid Christmas tree, because the top of the 2nd triangle must be in a column between 3 and 5, inclusive.
..###
.#...
###..
You need to find the K-Christmas tree with the largest number of green cells.
The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of three lines:
For each test case, output one line containing Case #x: y
, where x
is the test case number (starting from 1) and y
is the number of green cells in the largest K-Christmas tree. If there is no K-Christmas tree, output 0.
1 ≤ T ≤ 100.
Memory limit: 1GB.
1 ≤ M ≤ 100.
1 ≤ N ≤ 100.
Each cell in the grid is either .
or #
.
Time limit: 30 seconds.
K = 1.
Time limit: 80 seconds.
1 ≤ K ≤ 100.
4 3 5 1 ..#.. .###. ##### 3 5 1 ..... ..... ..... 4 5 1 ##### ##### ##### ##### 4 5 2 ##### ##### ##### #####
Case #1: 9 Case #2: 0 Case #3: 9 Case #4: 10
In sample case #1, the largest 1-Christmas tree has 9 green cells:
..#..
.###.
#####
In sample case #2, there is no 1-Christmas tree.
In sample case #3, one largest 1-Christmas tree with 9 green cells is:
#####
#####
#####
#####
In sample case #4, one largest 2-Christmas tree with 10 green cells is:
#####
#####
#####
#####