解题报告 『生活大爆炸版石头剪刀布(模拟)』

原题地址

虽说此题难度不大,但依然有着很精妙的做法。

比如下面这位大佬的代码:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (register int i = (a); i <= (b); i++)

int n, Na, Nb, ans = 0, bns = 0;
int a[200 + 5], b[200 + 5], vs[5][5] = {{0, 0, 1, 1, 0}, {1, 0, 0, 1, 0}, {0, 1, 0, 0, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}};

int read() {
    int x = 0, flag = 0;
    char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') {
        flag = 1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + ch - '0';
        ch = getchar();
    }
    return flag ? -x : x;
}

void write(int x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    n = read(), Na = read(), Nb = read();
    rep(i, 0, Na - 1) a[i] = read();
    rep(i, 0, Nb - 1) b[i] = read();
    rep(i, 0, n - 1) {
        ans += vs[a[i % Na]][b[i % Nb]];
        bns += vs[b[i % Nb]][a[i % Na]];
    }
    write(ans);
    printf(" ");
    write(bns);
    return 0;
}
View Code

 完全不用加注释有木有?

 

仿照着这份代码我自己也敲了一份,结果居然WA了四个点

最后发现按照习惯我的循环是从1开始的……

但是

i % Na || i % Nb

是可以为0的呀!

我果然还是太蒻了OGCOTZ。

 

转载于:https://www.cnblogs.com/Kirisame-Marisa/p/10309728.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值