2020 Multi-University Training Contest 8

Auto-correction
Breaking Down News

Clockwise or Counterclockwise

#include 
using namespace std;
typedef long long ll;

int main() {
     

    int t;
    scanf("%d", &t);

    while (t--) {
     
        ll x1, y1, x2, y2, x3, y3;
        scanf("%lld%lld%lld%lld%lld%lld", &x1, &y1, &x2, &y2, &x3, &y3);
        if ((x1 - x3) * (y2 - y3) - (y1 - y3) * (x2 - x3) > 0)
            printf("Counterclockwise\n");
        else 
            printf("Clockwise\n");
    }
    return 0;
}

Discovery of Cycles
Easy NPC Problem

Fluctuation Limit

#include 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1e6 + 10;

int n;
vector<pll> res;
ll l, r, a, b, k, ans[N];

int main() {
     
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T;
    cin >> T;
    while (T--) {
     
        res.clear();
        int flag = 0;

        cin >> n >> k;
        cin >> l >> r;
        res.push_back({
     l, r});
        for (int i = 1; i < n; i++) {
     
            l -= k;
            r += k;

            cin >> a >> b;
            l = max(l, a);
            r = min(r, b);

            if (!flag) {
     
                if (l > r) {
     
                    flag = 1;
                } else {
     
                    res.push_back({
     l, r});
                }
            }
        }

        if (flag) {
     
            cout << "NO" << endl;
        } else {
     
            cout << "YES" << endl;
            ans[n - 1] = res[n - 1].first;
            l = res[n - 1].first;
            for (int i = n - 2; i >= 0; i--) {
     
                if (res[i].first < l) 
                    ans[i] = max(res[i].first, l - k);
                else 
                    ans[i] = res[i].first;
                l = ans[i];
            }

            for (int i = 0; i < n; i++) {
     
                cout << ans[i] << (i == n - 1 ? "\n" : " ");
            }
        }
    }
    return 0;
}

Gaming of Co-prime Disallowance

Hexagon

#include 
using namespace std;

int n;
const int N = 1e6 + 10;
int id[505];
char s1[N],s2[N];

int main() {
     

    int x = 500, y, z, tot = 0;
    // 偶数
    while (x) {
     
        id[x] = tot;
        y = x - 2;
        for (int i = 1; i <= x; i++) {
     
            s1[tot++] = '1';
            s1[tot++] = '3';
        }

        for (int i = 1; i <= y; i++) {
     
            s1[tot++] = '4';
            s1[tot++] = '2';
        }
        s1[tot++] = '4';

        for (int i = 1; i <= y; i++) {
     
            s1[tot++] = '5';
            s1[tot++] = '3';
        }
        s1[tot++] = '5';

        if (y) {
     
            for (int i = 1; i <= y; i++) {
     
                s1[tot++] = '6';
                s1[tot++] = '4';
            }
            s1[tot++] = '6';

            for (int i = 1; i <= y; i++) {
     
                s1[tot++] = '1';
                s1[tot++] = '5';
            }
            s1[tot++] = '1';
            
            z = y - 2;
            for (int i = 1; i <= z; i++) {
     
                s1[tot++] = '2';
                s1[tot++] = '6';
            }
            s1[tot++] = '2';
            s1[tot++] = '3';
        }
        x -= 2;
    }
    s1[tot++] = '\0';
    
    // 奇数
    x = 499;
    tot = 0;
    while (x > 1) {
     
        id[x] = tot;
        x -= 2;
        y = x - 1;

        s2[tot++] = '2';
        s2[tot++] = '3';

        for (int i = 1; i <= x; i++) {
     
            s2[tot++] = '1';
            s2[tot++] = '3';
        }

        for (int i = 1; i <= x; i++) {
     
            s2[tot++] = '4';
            s2[tot++] = '2';
        }
        s2[tot++] = '4';
        
        for (int i = 1; i <= x; i++) {
     
            s2[tot++] = '5';
            s2[tot++] = '3';
        }
        s2[tot++] = '5';

        for (int i = 1; i <= x; i++) {
     
            s2[tot++] = '6';
            s2[tot++] = '4';
        }
        s2[tot++] = '6';

        for (int i = 1; i <= x; i++) {
     
            s2[tot++] = '1';
            s2[tot++] = '5';
        }
        s2[tot++] = '1';

        if (y) {
     
            for (int i = 1; i <= y; i++) {
     
                s2[tot++] = '2';
                s2[tot++] = '6';
            }
        }
        s2[tot++] = '2';
        s2[tot++] = '3';
    }
    s2[tot++] = '\0';

    int T;
    cin >> T;
    while (T--) {
     
        cin >> n;
        if (n & 1) {
     
            printf("%s\n", s2 + id[n]);
        } else {
     
            printf("%s\n", s1 + id[n]);
        }
    }
    return 0;
}

Isomorphic Strings

#include 
using namespace std;
typedef unsigned long long ull;
const ull base = 131;
const int N = 5e6 + 10;
int n, m;
char s[N];
int cnt[27];
unordered_map<ull, int> mp;
ull F[N];
ull f[N], p[N];

ull Hash(int l, int r, bool rsh = true) {
     
    return rsh ? F[r] - F[l - 1] * p[r - l + 1] : f[r] - f[l - 1] * p[r - l + 1];
}

bool check(int k) {
     
    mp.clear();
    //init
    int len = n / k;
    for (int i = 1; i <= len; i++) {
     
        f[i] = F[i];
    }
    for (int i = len + 1, lim = len * 2; i <= lim; i++) {
     
        f[i] = f[i - 1] * base + s[i - len] - 'a' + 1;
    }
    
    for (int i = 1; i <= len; i++) {
     
        mp[Hash(i, i + len - 1, 0)] = 1;
    }

    for (int i = len + 1; i <= n; i += len) {
     
        if (mp[Hash(i, i + len - 1)] != 1) {
     
            return false;
        }
    }
    return true;
}

vector<int> v;

int main() {
     
    p[0] = 1;
    F[0] = 0;
    for (int i = 1, lim = N - 10; i <= lim; i++) {
     
        p[i] = p[i - 1] * base;
    }

    int T;
    scanf("%d", &T);
    while (T--) {
     
        scanf("%d", &n);
        scanf("%s", s + 1);
        for (int i = 1; i <= n; i++) {
     
            cnt[s[i] - 'a']++;
        }
        for (int k = 1; k * k <= n; k++) {
     
            if ((n % k) == 0) {
     
                int f = 1;

                if (k > 1) {
     
                    for (int i = 0; i < 26; i++) {
     
                        if ((cnt[i] % k) != 0) {
     
                            f = 0;
                            break;
                        }
                    }
                    if (f) v.push_back(k);
                }

                m = n / k;
                if (m > 1 && (n % m == 0)) {
     
                    f = 1;
                    for (int i = 0; i < 26; i++) {
     
                        if ((cnt[i] % m) != 0) {
     
                            f = 0;
                            break;
                        }
                    }
                    if (f) v.push_back(m);
                }
            }
        }

        int f = 0;
        if (v.empty()) {
     
            //直接no
        } else {
     
            for (int i = 1; i <= n; i++) {
     
                F[i] = F[i - 1] * base + (s[i] - 'a' + 1);
            }

            for (int k : v) {
     
                if (check(k)) {
     
                    f = 1;
                    break;
                }
            }
        }

        if (f) puts("Yes");
        else  puts("No");
        //init
        for (int i = 0; i < 26; i++) {
     
            cnt[i] = 0;
        }
        v.clear();
    }
    return 0;
}

Jumping on a Cactus
Kidnapper’s Matching Problem
Linuber File System

你可能感兴趣的:(多校)