P1076 寻宝

水古董题也不轻松。。。


题目都这么说了,就照它的意思去模拟吧。

但是注意:\(0 \leq x \leq 100000\),不优化是会T的。但是优化也非常容易。

只需要记录下每一层楼有梯子的房间数cnt[i]即可。

然后多余的数就是在重复转圈,删除掉即可。

后来发现不能直接取模,在整除的时候加个特判就ok了。

话说没有讨论区的样例解释我是看不懂的。

代码:

#include<cstdio>

const int maxn = 10005, maxm = 105;
const int mod = 20123;
int a[maxn][maxm];
bool b[maxn][maxm];
int cnt[maxn];//一层楼有多少个
int n, m, ans;

int read()
{
    int ans = 0, s = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0')
    {
        if(ch == '-') s = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        ans = ans * 10 + ch - '0';
        ch = getchar();
    }
    return s * ans;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    n = read(), m = read();
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            b[i][j] = read(), a[i][j] = read();
            if(b[i][j]) cnt[i]++;
        }
    }
    int now = read();
    for(int i = 1; i <= n; i++)
    {
        int num = a[i][now];
        ans = (ans + num) % mod;
        if(num % cnt[i] == 0) num = cnt[i];
        else num = num % cnt[i];
        while(num)
        {
            if(b[i][now])
            {
                num--;
                if(num == 0) break;
            }
            now++;
            if(now >= m) now -= m;
        }
    }
    printf("%d\n", ans % mod);
    return 0;
}

转载于:https://www.cnblogs.com/Garen-Wang/p/9388393.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值