【NOIP2012】寻宝 模拟

22 篇文章 0 订阅
20 篇文章 0 订阅

【NOIP2012】寻宝 模拟

原来一直都理解错了题意……

记录一下每层有多少个有楼梯的房间

比如有 3 个房间有楼梯, 需要找到第 4 个房间, 那就相当于找到第 1 个房间

通过这样减少模拟次数。

代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
using namespace std;

#define MAXN (10100)
#define MAXM (110)
#define mod (20123)
bool dr[MAXN][MAXM];
int nxt[MAXN][MAXM], cnt[MAXN];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++ i)
        for(int j = 0; j < m; ++ j)
            cin >> dr[i][j], scanf("%d", &nxt[i][j]);

    for(int i = 1; i <= n; ++ i)
        for(int j = 0; j < m; ++ j)
            if(dr[i][j])
                cnt[i] ++;
    int fang;
    cin >> fang;
    int ans = 0;
    for(int ceng = 1; ceng <= n; ++ ceng)
    {
        ans = (ans%mod + nxt[ceng][fang]%mod)%mod;
        int x = nxt[ceng][fang]%cnt[ceng];
        if(!x) x = cnt[ceng];
        while(x)
        {
            if(dr[ceng][fang]) x --;
            if(x) fang ++; fang%=m;
        }
    }
    cout << ans%mod << endl;
    return 0;
}

大样例:

input
10 10
1 3
0 8
0 8
0 4
1 8
1 9
0 4
1 10
1 4
0 7
1 3
1 10
0 5
0 4
1 1
0 10
1 4
0 6
0 4
0 1
1 3
1 9
1 5
1 8
1 6
1 4
1 7
1 8
0 7
0 10
1 9
1 7
1 1
1 1
0 6
0 4
1 7
0 1
1 7
1 3
1 1
1 8
1 3
0 3
1 3
0 3
1 8
1 5
1 3
1 8
1 4
1 8
0 10
0 10
1 6
0 7
1 7
1 9
1 7
1 6
1 4
1 7
0 10
1 7
1 8
0 2
1 10
0 8
0 9
0 10
1 2
1 2
0 3
0 4
0 2
1 1
1 2
0 5
1 7
1 6
1 6
1 10
1 5
0 6
0 3
0 3
1 1
1 6
0 4
1 4
1 8
1 3
1 7
1 6
0 2
1 3
0 3
0 2
1 1
1 1
8

output
50
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值