Вы находитесь на странице: 1из 4

Context

Given a 2D Array, A :
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
We define an hourglass in A to be a subset of values with indices falling in this pattern
in A's graphical representation:
a b c
d
e f g
There are hourglasses in A, and an hourglass sum is the sum of an hourglass' values.
Task
Calculate the hourglass sum for every hourglass in A, then print the maximum hourglass
sum.
Note: If you have already solved the Java domain's Java 2D Array challenge, you may
wish to skip this challenge.

Input Format

There are 6 lines of input, where each line contains 6 space-separated integers
describing 2D Array A ; every value in A will be in the inclusive range of -9 to 9 .

Constraints
-9 <= A[i][j] <= 9
0 <= i, j <= 5

Output Format

Print the largest (maximum) hourglass sum found in .

Sample Input
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0

Sample Output
19

Explanation

contains the following hourglasses:


1 1 1 1 1 0 1 0 0 0 0 0
1 0 0 0
1 1 1 1 1 0 1 0 0 0 0 0

0 1 0 1 0 0 0 0 0 0 0 0
1 1 0 0
0 0 2 0 2 4 2 4 4 4 4 0

1 1 1 1 1 0 1 0 0 0 0 0
0 2 4 4
0 0 0 0 0 2 0 2 0 2 0 0

0 0 2 0 2 4 2 4 4 4 4 0
0 0 2 0
0 0 1 0 1 2 1 2 4 2 4 0
The hourglass with the maximum sum (19) is:
2 4 4
2
1 2 4

Connecting Towns

2) Gandalf is travelling from Rohan to Rivendell to meet Frodo but there is no direct
route from Rohan (T1) to Rivendell (Tn).
But there are towns T2,T3,T4...Tn-1 such that there are N1 routes from Town T1 to T2, and in
general, Ni routes from Tito Ti+1 for i=1 to n-1 and 0 routes for any other Ti to Tj for j
i+1

Find the total number of routes Gandalf can take to reach Rivendell from Rohan.

Note
Gandalf has to pass all the towns Ti for i=1 to n-1 in numerical order to reach Tn.
For each Ti , Ti+1 there are only Ni distinct routes Gandalf can take.
Input Format
The first line contains an integer T, T test-cases follow.
Each test-case has 2 lines. The first line contains an integer N (the number of towns).
The second line contains N - 1 space separated integers where the ith integer denotes
the number of routes, Ni, from the town Ti to Ti+1
Output Format
Total number of routes from T1 to Tn modulo 1234567
http://en.wikipedia.org/wiki/Modular_arithmetic
Constraints
1 <= T<=1000
2< N <=100
1 <= Ni <=1000
Sample Input
2
3
1 3
4
2 2 2
Sample Output
3
8
Explanation
Case 1: 1 route from T1 to T2, 3 routes from T2 to T3, hence only 3 routes.
Case 2: There are 2 routes from each city to the next, at each city, Gandalf has 2 choices
to make, hence 2 * 2 * 2 = 8.

Restaurant

Martha is interviewing at Subway. One of the rounds of the interview requires her to cut
a bread of size l*b into smaller identical pieces such that each piece is a square having
maximum possible side length with no left over piece of bread.
Input Format

The first line contains an integer T. T lines follow. Each line contains two space separated
integers l and b which denote length and breadth of the bread.

Constraints
l <= T <=1000
1<= l , b <=1000

Output Format

T lines, each containing an integer that denotes the number of squares of maximum
size, when the bread is cut as per the given condition.

Sample Input 0
2
22
69

Sample Output 0
1
6

Explanation 0

The 1st testcase has a bread whose original dimensions are 2*2, the bread is uncut and is
a square. Hence the answer is 1.
The 2nd testcase has a bread of size 6*9. We can cut it into 54 squares of size 1*1, 6 of
size 3*3 . For other sizes we will have leftovers. Hence, the number of squares of
maximum size that can be cut is 6.

Вам также может понравиться