201907月赛 - 问题 H: 乾坤大挪移

发布时间 2023-12-04 21:08:11作者: ckxkexing

初步思考:记忆化搜索,但是复杂度好像有点高。

生成树的数据:

 

#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr << #x << " := " << x << endl;
#define bug cerr << "-----------------------" << endl;
#define FOR(a, b, c) for (int a = b; a <= c; ++a)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> PII;

template <class T>
void _R(T &x) {
    cin >> x;
}
void _R(int &x) {
    scanf("%d", &x);
}
void _R(ll &x) {
    scanf("%lld", &x);
}
void _R(double &x) {
    scanf("%lf", &x);
}
void _R(char &x) {
    scanf(" %c", &x);
}
void _R(char *x) {
    scanf("%s", x);
}
void R() {
}
template <class T, class... U>
void R(T &head, U &... tail) {
    _R(head);
    R(tail...);
}

template <typename T>
inline T read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    return x = f ? -x : x;
}

const ll inf = 0x3f3f3f3f3f3f3f3f;

const int mod = 1e9 + 7;

/**********showtime************/
const int maxn = 309;
int roots[maxn], a[maxn], b[maxn], c[maxn], X[maxn];
int u[maxn], v[maxn];
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) R(roots[i]);
    for (int i = 1; i <= m; i++) R(a[i]);
    for (int i = 1; i <= m; i++) R(b[i]);
    for (int i = 1; i <= m; i++) R(c[i]);

    for (int i = 1; i <= m; i++) {
        X[0] = c[i];
        for (int k = 1; k <= n - 2; k++)
            X[k] = (a[i] * X[k - 1] + b[i]) % 1000000007;
        cout << "-----------" << i << "---------------" << endl;
        for (int j = 0; j <= n - 2; j++) {
            u[j] = (roots[i] + j + 1) % n;
            v[j] = (roots[i] + (X[j] % (j + 1))) % n;
            ///                连接 T(i) 的 u[j] 与 v[j]之间的边
            cout << u[j] << " " << v[j] << endl;
        }
    }

    return 0;
}
View Code