Los P1076 Treasure Hunt Valley

Title Description

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, the other treasure F 0 has N layers, each 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 No. kkk 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.
Input and output format
input format:

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 lines, each two integers, separated by a space between each line within a room is described the case where the first (i-1) × M + j (i-1) represents the i-th row layer number j-1 where the room (i = 1,2, ..., Ni = 1,2, ..., Ni = 1,2, ..., N; j = 1,2, ..., Mj = 1,2, ... , Mj = 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 formats:

An integer that represents the key to open the chest, this number may be very large, please output the results to the modulo 20123.

Input Output Sample
Input Sample # 1:

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

Sample Output # 1

5

Explanation

【data range】

For 50% of the data, there are 0 <N≤1000,0 <x≤100000
to 100% of the data, there have 0 <N≤10000,0 <M≤100,0 <x≤1,000,0000

NOIP 2012 universal set of second title

This question is the general idea is to simulate. Open a number of cycles for the door of a room. Reach a door to look at the statistics. Accumulating the number of doors, gates, 1, 0 otherwise the number of statistics, sum [i]. Since the title except said top layer, do not i <= n, the direct use of i <n as the end condition. i ++ simulation upstairs. But also to determine is not a ring

#include<bits/stdc++.h>
using namespace std;
int sum=0;
int n,m;
int a[10100][1010],b[10010][1010];
int c[100100];
int tre;
int main(){
cin >> n >> m;
for(int i=1;i<=n;i++)//读入
    for(int j=0;j<m;j++){
        cin >> a[i][j] >> b[i][j];
        if(a[i][j]==1){
            c[i]++;//统计门数
        }
    }

cin >> tre;
int ans=b[1][tre];
int j=tre;
int i=1;//预处理
while(i<n){//while循环结束条件
    int x,y=false;
    x=b[i][j]%c[i];
    if (x==0){
        x=c[i];
    } 
    while(y+a[i][j]<x){//模拟题意
        y=y+a[i][j];
        j++;
        if(j==m){
        j=0;
    }
    
    }
        i++;有楼梯,上楼
        ans=ans+b[i][j];//加上指示牌数字
        ans%=20123;//边走边模
}
cout << ans%20123;
return 0;
}

Guess you like

Origin www.cnblogs.com/A-Konnyaku/p/10993485.html