| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10864 | Laser Beam |
|
| 10868 | Pour Water (8 Directions) |
|
| 10869 | Array Sort |
|
Description
Consider a room of size H*W (3<=H < 10000,3<=W < 10000) in which its four walls are covered by mirrors. You need to simulate the laser beam reflection in the room and print out the k-th ( 0 < k < 10000)reflection point.
We assume that the laser beam is always emitted from the left mirror and moves in the upper-right direction at an angle of 45 degrees. More specifically, the starting point can be represented by (r, 1) where 1<r<H. The laser beam will stop if it hits any corner of the room. Also, each point can only reflect the laser beam once. That is, the second time the laser beam hits the same point, the process of reflection stops.
For example, if the room size is 5*5 and the laser beam starts at (3,1), then the first point it hits is (3,1), the second point is (1,3), the third point is (3,5), and so on. If k=3 you need to print out (3,5).
If the laser beam stop before the k-th reflection, you need to print out coordinate of the stop point. For example, if k =10 and the first point is (3,1), you need to print out (3,1) because the laser beam stops at (3,1).
Input
The first line is the height and width of the room.
The second line is the starting point (the first reflection point).
The third line is k, which means you need to print out the k-th reflection point.
Output
The coordinate of the k-th reflection point.
Note that you DO NOT need to print a newline character ‘\n’ at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A farmer has a crop land. The land consists of stones (S) and holes (H) as illustrated in the following figure. Note that there is only one hole on the land’s first row.
|
S |
S |
H |
S |
S |
|
H |
H |
H |
H |
S |
|
H |
S |
S |
S |
S |
|
S |
H |
S |
H |
H |
|
S |
H |
S |
S |
S |
The farmer decides to water his crops, so he pours some water through the hole on the first row into the land. Assume that the amount of water is infinite, and the water can move in the eight directions: up, down, left, right, upper-left, upper-right, lower-left, lower-right. Please write a program to find out where the water would reach.
For example, you are given a coordinate (0,2) representing the entrance and a table representing the farmer’s land initially:
|
S |
S |
H |
S |
S |
|
H |
H |
H |
H |
S |
|
H |
S |
S |
S |
S |
|
S |
H |
S |
H |
H |
|
S |
H |
S |
S |
S |
After the farmer pours water into the land, water floods throughout the holes of the land. Finally, a portion of the holes will be filled with water like the following table.
|
S |
S |
W |
S |
S |
|
W |
W |
W |
W |
S |
|
W |
S |
S |
S |
S |
|
S |
W |
S |
H |
H |
|
S |
W |
S |
S |
S |
where W means the corresponding hole is filled with water.
Note that
1. This problem involves three files.
- function.h: Function definition of flooding.
- function.c: Function implementation of flooding.
- main.c: A driver program to test your implementation.
You will be provided with main.c and function.h, and asked to implement function.c.
2. For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose c compiler)
Step 2. Check the results and debug your program if necessary.
Hints:
function.h
main.c
Input
The first line has an integer N(1<=N<=100), which means the number of test cases.
For each case, the first line has three integers. The first and second integers R and C (3<=R, C<=500) represent the numbers of rows and columns of the land, respectively. The total number of elements in the land is thus R x C. The third integer X (0<=X<=C-1) means the column of the entrance at the first row. The coordinate of the entrance is thus (0,X). The following R lines, each containing C characters, specify the elements of the farmer’s land.
Output
Print out all elements of the lands row-by-row, and there is a '\n' at the end of each line. The states of all lands should be separated by a new line character (\n).
Sample Input Download
Sample Output Download
Partial Judge Code
10868.cPartial Judge Header
10868.hTags
Discuss
Description
Given two dimensional array of size M x N(1 < M,N < 10).
We want to sort for all of the two dimensional array value
For example:
|
5 |
1 |
3 |
11 |
25 |
|
45 |
82 |
97 |
73 |
63 |
|
13 |
47 |
34 |
26 |
14 |
After sorted
|
1 |
3 |
5 |
11 |
13 |
|
14 |
25 |
26 |
34 |
45 |
|
47 |
63 |
73 |
82 |
97 |
Submit only your function.c into the submission block. (Please choose C compiler)
The bubble sort algorithm:
/* Using bubble sort to rearrange an array A[n] */
for (i = 0; i < n; i++) {
for (j = 1; j < n - i; j++) {
if (A[j-1] > A[j]) {
/* swap A[j-1] A[j] */
}
}
}
main.c
#include <stdio.h>
#include "function.h"
int main()
{
int M,N;
int i,j;
scanf("%d%d", &M, &N);
int array[M][N];
for(i = 0; i < M; i++)
for(j = 0; j < N; j++)
scanf("%d", &array[i][j]);
sortArray( M, N, array);
printResult( M, N, array);
return 0;
}
function.h
void swap(int *a, int *b);
void sortArray(int M, int N, int (*array)[N]);
void printResult(int M, int N, int (*array)[N]);
Input
The first line is two dimensional array size M and N.(1 <M,N <10)
The other line are value of array to be sorted.
Output
Each line shows output of sorted array.
All of the integers in the same line are separated by a space, and there is a '\n' at the end of each line.