| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11237 | Simple Tangram |
|
| 11238 | Light Reflection |
|
| 11239 | Pour Water |
|
| 11240 | license |
|
| 11241 | Simple Addition |
|
| 11242 | Game visiting list |
|
Description
The tangram is a dissection puzzle consisting of seven flat shapes, called tans, which are put together to form shapes. For example, we can use the given seven tans to form a bird as follows:

In this problem, let’s play a simplified tangram. You are asked to form a shape on a M*N (0<M,N≦50) board, which is initially plotted a symbol ’-’ at each location. Now, we consider only two tans as follows:

- You will be given a symbol (Triangle (T) or Square (Q)) representing the desired tan, the rotated angle(only 0, 90, 180 or 270 degrees), the height or side of the tan, and the assigned coordinate of the tan’s vertex(頂點).
Specifically, when rotating a tan, the tan is fixed at its vertex, and rotated clockwise (by degrees 0, 90, 180, or 270.)
Input
The input contains several lines. The first line contains two numbers representing the board’s height and width. The following line contains one symbol and four numbers. The first symbol represents the tan you should put on board. The second number represents the rotating degree of the tan. The third number represents the height or side of the tan. The fourth and fifth numbers represent the coordinate of the tan’s vertex.
An input line containing only ’x’ represents the end of the input.
Output
The output should print the M*N board. Note that there's a '\n' at the end of last line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Consider a room of size H*W (3<=H,3<=W) in which its four walls are covered by mirrors. You need to simulate the light reflection in the room and print out the k-th reflection point.
We assume that the light 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 light will stop if it hits any corner of the room .
For example, if the room size is 5*6 and the light starts at (3,1), then the first point it hits is (3,1), the second point is (1,3), the third point is (4,6), and so on. If k=3 you need to print out (4,6).
If the light hits a corner before the k-th reflection, you need to print out coordinate of that corner. For example, if k =10 and the first point is (3,1), you need to print out (1,1) because the light stops at (1,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 |
S |
H |
H |
H |
|
H |
H |
H |
S |
S |
|
H |
H |
S |
H |
H |
|
H |
S |
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 four directions: up, down, left, 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 |
S |
H |
H |
H |
|
H |
H |
H |
S |
S |
|
H |
H |
S |
H |
H |
|
H |
S |
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 |
S |
W |
W |
W |
|
W |
W |
W |
S |
S |
|
W |
W |
S |
H |
H |
|
W |
S |
S |
S |
S |
where W means the corresponding hole is filled with water.
You will be provided with the following sample code, and asked to implement function "flooding".
#include <stdio.h>
void flooding(int R, int C, int pr, int pc);
char Map[505][505];
int main(void){
int N,R,C,X,i,j,k;
scanf("%d", &N);
for(k=0;k<N;k++){
scanf("%d%d%d", &R, &C, &X);
for(i=0;i<R;i++){
for(j=0;j<C;j++){
Map[i][j] = ' ';
}
}
for(i=0;i<R;i++){
scanf("%s", Map[i]);
}
flooding(R,C,0,X);
for(i=0;i<R;i++){
for(j=0;j<C;j++){
printf("%c", Map[i][j]);
}
printf("\n", Map[i][j]);
}
if(k<N-1)
printf("\n", Map[i][j]);
}
return 0;
}
void flooding(int R, int C, int pr, int pc){
/*your code*/
}
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 row and column 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
Tags
Discuss
Description
There are N license. Each license has four-digit integer, each integer between 1 to 9. For example, if N=7, the input may look like
7
1324
5566
3578
4123
5656
4312
9847
We want to get the licenses that use the same digits and the digits should be sorted from small to large. For example, 1324, 4123, and 4312 are the combination of the same digits (1, 2, 3, and 4). We want to get 1234. Similarly, 5566 and 5656 are the combination of the same digits (5, 5, 6, and 6). We want to get 5566.
For output, we list the modified licenses in an increasing order line by line, so the output will look
1234
5566
<Hint>
You may consider the following algorithm:
0. Create a character array (char str[5];) for storing the input integers and create an array which is initialed to zero (int HIT[10000];) to record the occurrences of input integers.
1. Read the number of input integers and store it in variable N (scanf("%d", &N);).
2. For each of the next N integers, do
2.1 Read the four-digit integer and store it as a four-character string in str.
2.2 Use the bubble sort algorithm to rearrange the four characters.
2.3 Convert the rearranged string to an integer m and increase the value of the corresponding element of the HIT array by 1 (HIT[m]++;).
3. Check each element of the HIT array; if its value is larger than 2, print the corresponding integer.
The bubble sort algorithm:
/* Using bubble sort to rearrange an array A[n] */
for (i = n; i > 0; i--) {
for (j = 1; j < i; j++) {
if (A[j-1] > A[j]) {
/* swap A[j-1] A[j] */
}
}
}
Input
The first line contains a number N (1<=N<=100).
The next N lines provide the N four-digit integers.
Output
Each line shows a modified unique integer as explained in the problem description.
Remember to print a newline at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Four arrays A, B, C and D with size MxN. B, C, D are stored in an array of pointers, and A is stored in a separated array. The task is to add the designated elements of A and the corresponding element from a chosen array of B, C, D, and output the result.
Take sample input as an example. Size of the arrays are 3 rows by 2 columns, initial values are as the form below. Input number “2” in the sixth line indicates D is chosen array and we want the sum of elements with two indices (1,0), (2,0)
Therefore, the answer is A(1,0)+D(1,0)+A(2,0)+D(2,0)=2+8+4+10=24
You will be provided with the following sample code, and asked to implement function "addition".
#include <stdio.h>
int addition(int*, int, int*[], int*, int);
int main(void) {
int a[50][50], b[50][50], c[50][50], d[50][50];
int index_to_add[20];
int *entry[3];
int i, j, m, n, array_num, num_ind;
scanf("%d %d", &m, &n);
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &a[i][j]);
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &b[i][j]);
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &c[i][j]);
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &d[i][j]);
scanf("%d", &array_num);
scanf("%d", &num_ind);
for(i=0; i<num_ind*2; i=i+2)
scanf("%d %d", &index_to_add[i], &index_to_add[i+1]);
entry[0] = &b[0][0];
entry[1] = &c[0][0];
entry[2] = &d[0][0];
printf("%d\n", addition(&a[0][0], array_num, entry, index_to_add, num_ind));
return 0;
}
int addition(int* ptr_a, int array_num, int* entry[], int* index_to_add, int num_ind){
/*your code*/
}
Input
The first line is the size of arrays, M rows by N columns. The following four lines are initial values arranged by row major. The sixth line tells B, C or D is chose. The next line is the number of elements k to be summed. And the last k lines are the row and column indices of elements to be add. 0 < M, N < 50. 0 < k < 10. Index starts from 0.
Output
An integer, sum of desired elements.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Consider a game that has N NPCs (non-player characters), numbered from 1 to N. Each NPC will give the player a list of some other NPCs for the player to visit in order. If the list of the 1st NPC is 2 3 0, then the player needs to visit the 2nd NPC and goes on checking the list of the 2nd NPC. Now, if the list of the 2nd NPC is 4 5 0, then the player needs to visit the 4th NPC and goes on checking the list of the 4th NPC, … Each list is ended by a number 0, indicating that there is no more NPCs to visit, and only by then the player can go back to the previous NPC to continue checking the unfinished list.
Given the visiting lists of all NPCs, print the NPCs visited by the player one by one according to the order described by their visiting lists. Note that the player always starts by visiting the first NPC.
You will be provided with the following sample code, and asked to implement function "findNPC".
#include <stdio.h>
#include <stdlib.h>
int NPClist[100][20];
void findNPC(int num);
int main() {
int n, i, j;
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(j = 0; ; j++) {
scanf("%d", &NPClist[i][j]);
if(NPClist[i][j] == 0) break;
}
}
findNPC(1);
return 0;
}
void findNPC(int num){
/*your code*/
}
Input
The first line of the input is an integer N indicating the total number of NPCs.
For the next N lines, the ith line contains the visiting list of the ith NPC (i = 1~N). The visiting list of each NPC is ended by 0.
Output
Display all the visited NPCs in order. Note that you need to print a newline character ‘\n’ after each number, that is, just one number will be shown in each line of the output.