2017.8.22 ACM 训练赛 题解

zerol edited 6 年,8 月前

这里你们看到的题目名字是之前取的。

模拟题 - 至多交换两次

https://www.hackerrank.com/challenges/new-year-chaos/editorial

简单题 - 我很好奇

https://www.hackerrank.com/challenges/easy-gcd-1/editorial

数学题 - Unlimited Blade Works

https://www.hackerrank.com/challenges/akhil-and-gf/editorial
另解

#include <bits/stdc++.h>
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
using namespace std;
typedef long long LL;

LL mul(LL a, LL b, LL m) {
    LL ret = 0;
    while (b) {
        if (b & 1) {
            ret += a;
            if (ret >= m) ret -= m;
        }
        a += a;
        if (a >= m) a -= m;
        b >>= 1;
    }
    return ret;
}


LL pown(LL x, LL n, LL MOD) {
    LL ret = 1; x %= MOD;
    while (n) {
        if (n & 1) ret = mul(ret, x, MOD);
        x = mul(x, x, MOD);
        n >>= 1;
    }
    return ret;
}

LL T, n, m;
int main() {
    cin >> T;
    while (T--) {
        cin >> n >> m;
        cout << (pown(10, n, m * 9) + m * 9 - 1) % (m * 9) / 9 << endl;
    }
}

STL题 - 线段覆盖

https://www.hackerrank.com/challenges/x-and-his-shots/editorial

智商题 - GOSICK

https://www.hackerrank.com/challenges/kitty-and-katty/editorial

DP(动规)题 - 移位异或和

https://www.hackerrank.com/challenges/xor-and-sum/editorial

动规(DP)题 - 子集质数异或和

https://www.hackerrank.com/challenges/prime-xor/editorial

数据结构题 - 点对总费用

https://www.hackerrank.com/challenges/direct-connections/editorial

Comments