You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 10010, M = 110, mod = 20123;
int n, m, k;
int a[N][M], b[N];
int num[N][M];
int main() {
scanf("%d%d", &n, &m);
int res = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
scanf("%d%d", &a[i][j], &num[i][j]);
b[i] += a[i][j]; // 本层的有楼梯房间数量
}
scanf("%d", &k); // 第一层入口
for (int i = 0; i < n; i++) {
int t = num[i][k]; // 显示的数字
res = (res + t) % mod; // 加上后取模,根据题意累加答案
t %= b[i]; // 数字模每行的房间数量
if (!t) t = b[i]; // 如果模为零则走b[i]步
// 走t步后是哪个房间号
int sum = 0;
while (sum < t) { // 走完求得的距离
sum += a[i][k]; // 当有楼梯时才算一步(题目描述的是第x个有楼梯的房间所以有楼梯才算一次移动)
if (sum == t) break; // 走完当前的k就是停留的房间号
k++; // 下一个房间
if (k == m) k = 0; // 不能越界回到0号房间
}
}
// 输出答案
printf("%d\n", res);
return 0;
}