Noip treasure hunt

1958: [group] 12NOIP popular treasure hunt


Time limit: 1000 ms memory limit: 131072 KB
submitted Number: Number 116 by: 61 

Description [title]

Legend far away on the top floor of the treasure hidden treasures attractive. Xiao Ming arduous journey finally found the Treasure House legendary treasure on end in front of a wooden floor, written in large letters above: a treasure hunt instructions. Content of the description is as follows:

Treasure total floor layer N + 1, the top layer is the top, the top having a room inside hidden treasures. In addition to the top layer, and another floor treasure N layers, each layer M room, press the M circle counterclockwise rooms are numbered 0, ..., M-1. Some rooms have access to the floor of the staircase, each floor design may be different. Each room has a sign, a figure on the sign x indicates the counterclockwise direction starting from the room to select the x-th stairs room (the room number is assumed K), from the upstairs room, after reaching the upstairs room on the k-th layer. For example, currently writing on signs the room 2, press counterclockwise began to try to find the first two stairs rooms upstairs from the room.

If the current staircase leading to the upper room itself, the room as the first room there are stairs. The last red treasure instructions in large print reads: "treasure hunt Notes: helping you find the numbers on each floor upstairs room signs (that is, the numbers on the signs within each of the first to enter the room) the sum of the open chest key. "

Please help Xiao Ming figure this key to open the chest.

 

[Enter]

The first line of two integers N and M, separated by a space between. N represents the total floor Treasure addition top floors N, M is in addition to top each floor M room.

Next N * M rows, each row two integers, separated by a space between each line within a room is described the case where the first (i-1) * M + j represent the i-th row j-1 Layer No. the conditions of the room (i = 1, 2, ..., N; j = 1, 2, ..., M). The first integer indicates whether the room has stairs leading to the layer (0 for no, 1 expressed), the second integer number representing the signs. Note that climbed on the room floor must also reach the stairs j j number of rooms from the room number.

The last line, an integer that represents the beginning of a treasure hunt Xiao Ming into the room from the ground floor a few numbers Booty (Note: the room numbering starts at 0).

 

[Output]

Output only one line, an integer that represents the key to open the chest, this number may be very large, please output the results to the modulo 20123.

 

[Sample input]

2 3
1 2
0 3
1 4
0 1
1 5
1 2
1

[Sample Output]

5

【prompt】

Example Description [O]

level one:

0 room with stairs leading to the top, the numbers on the signs is 2;

1 room, without stairs leading to the top, the numbers on the signs is 3;

2 room, stairs leading to the top, the numbers on the signs is 4;

Second floor:

0 room, no stairs leading to the top, the numbers on the signs is 1;

1 room with stairs leading to the top, the numbers on the signs is 5;

2 room, stairs leading to the top, the numbers on the signs is 2;

After Xiaoming first into a first layer (bottom) room number 1, number of signs that are on the 3 and starting from this room, to select the third staircase into the room number of the room in the counterclockwise direction, upstairs room No. 2 reaches the second layer, that are on the digital sign is 2, because of the current itself stairs leading to the upper room, the room as the first room stairs. Thus, this time in the counterclockwise direction to select the second number is the staircase room room 1, after entering the stairs to the top floor. In this case the digital signage together under the above in mind, i.e., 3 + 2 = 5, the chest is open the key 5.

【data range】

For 50% of the data, there are 0 <N≤1000,0 <x≤10000;

To 100% of the data, there are 0 <N≤10000,0 <M≤100,0 <x≤1,000,000.

Code:

#include <bits / STDC ++ H.>
the using namespace STD;
#define N 20123
Long Long S [10005] [105], CH [10005] [105], T [10005] = {0}, ANS = 0, m, n, k, x = 0; // value will be large, with Long Long
int JS [105];
int main ()
{// s number on array storage signs, storing state arrays CH, t is the array of recording per layer number of stairs
Scanf ( "% LLD% LLD", & n-, & m);
for (int I =. 1; I <= n-; I ++)
{
for (int J = 0; J <m; J ++)
{
Scanf ( "% LLD% LLD", & CH [I] [J], & S [I] [J]); T [I] + = CH [I] [J];}
}
// added directly here, 0 does not affect the result, the following is the same
Scanf ( "% LLD", & K);
for (int I = 0; I <m; I ++) // initialize an array
JS [I] = I +. 1;
JS [m-. 1 ] = 0;
for (int I =. 1; I <= n-; I ++)
{
ANS + = S [I] [K];
T [I] = (S [I] [K] -1)% T [I] +1; // cycle of revolutions can be removed
x = 0;// Initialization
while (x <t [i] )
{
X = CH + [I] [k];
IF (X == T [I]) BREAK; // Once equal, the loop is exited, otherwise vary k
k = JS [k];
}
}
the printf ( "% LLD" ,% N ANS);
}

Guess you like

Origin www.cnblogs.com/Youio-bolg/p/Noip.html