2022年广东工业大学文远知行杯新生程序设计竞赛(10/13)

迫真算法部・ACの裏技

模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    bool ok1 = false, ok2 = false, ok3 = false;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (ok1 and ok2 and s == "V") {
            ok3 = true;
        }
        if (s == "CTRL") {
            ok1 = true;
        }
        if (ok1 and s == "C") {
            ok2 = true;
        }
        if (s == "UNCTRL") {
            ok1 = false;
        }
    }
    if (ok3) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

qqdd抢餐券

暴力模拟,或前缀和差分双指针

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int a[150];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t, k;
    cin >> t >> k;
    for (int i = 0; i < t; i++) {
        int x, y;
        cin >> x >> y;
        for (int j = x; j <= y; j++) {
            a[j]++;
        }
    }
    vector<pair<int, int>> z;
    for (int i = 0; i <= 120; i++) {
        int j = i;
        while (a[j] < k and j <= 120) {
            j++;
        }
        if (j > i) {
            z.push_back(make_pair(i, j - 1));
            i = j;
        }
    }
    cout << z.size() << '\n';
    for (auto it : z) {
        cout << it.first << "-" << it.second << '\n';
    }
    return 0;
}

智慧之神的简单题

模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i <= s; i++) {
        for (int j = i; j <= s; j++) {
            for (int k = j; k <= s; k++) {
                if (i + j + k <= s and i * j * k <= t) {
                    ans++;
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

赚硬币

数学,可知(A+B+C)*n=55,n=5或11,可知n只能为5,A+B+C=11,再根据题意暴力求解A=6,B=3,C=2,最后只有Alice和Mazige拿过第二,都试试就可以了

AC代码:
 

5 Mazige

柒小队打麻将

数学,模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mod = 10;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        LL k;
        cin >> k;
        int len = s.size();
        int n = s[len - 1] - '0';
        function<LL(LL, LL)> qp = [&](LL a, LL b) {
            LL res = 1;
            for (; b; b >>= 1, a = a * a % mod) {
                if (b & 1) {
                    res = res * a % mod;
                }
            }
            return res;
        };
        LL z = qp(9, k);
        cout << qp(n, z) << '\n';
    }
    return 0;
}

亚子和燐子的game

模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define int long long
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int z = a[i];
        mp[a[i]]++;
        while (z >= 3) {
            z /= 3;
            mp[z]++;
        }

    }
    bool ok = false;
    vector<int> z;
    for (auto it : mp) {
        if (it.second == n) {
            ok = true;
            z.push_back(it.first);
        }
    }
    if (not ok) {
        cout << "Lose\n";
        exit(0);
    }
    int ans = 0, x;
    x = *max_element(z.begin(), z.end());
    for (int i = 0; i < n; i++) {
        while (a[i] != x) {
            a[i] /= 3;
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

我最好的朋友

手玩一下发现当%4=0的时候是必败态,其他都是必胜态

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        LL n;
        cin >> n;
        if (n % 4 == 0) {
            cout << "Not Mazige\n";
        } else {
            cout << "Mazige\n";
        }
    }
    return 0;
}

马子哥的奖金

模拟,讨论k的奇偶性

显然两个两个判断更容易写,所以当k为奇数的时候应该先把最大值赋给答案

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k, cnt = 0;
    cin >> n >> k;
    vector<LL> a(n);
    bool ok = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > 0) {
            cnt++;
        } else if (a[i] == 0) {
            ok = true;
        }
    }
    sort(a.begin(), a.end(), [&](LL a, LL b) {
        return a > b;
    });
    LL ans = 1;
    int flag = 1, l = 0, r = n - 1;
    if (k & 1) {
        ans = a[0];
        k--;
        if (a[0] < 0) {
            flag = -1;
        }
        l++;
    }
    while (k) {
        if (1LL * flag * a[l] * a[l + 1] > 1LL * flag * a[r] * a[r - 1]) {
            ans = ans * a[l] % mod * a[l + 1] % mod;
            if (ans < 0) {
                flag = -1;
            } else {
                flag = 1;
            }
            l += 2;
            k -= 2;
        } else {
            ans = ans * a[r] % mod * a[r - 1] % mod;
            if (ans < 0) {
                flag = -1;
            } else {
                flag = 1;
            }
            r -= 2;
            k -= 2;
        }
    }
    if (ok) {
        ans = max(ans, 0LL);
    }
    cout << ans << '\n';
    return 0;
}

​​​​​​​奇迹和魔法都是存在的

根据题意,最后留下的只能是第一个或者比第一个数大的数,所以答案就是1+第一个数大的数的个数,数据范围小暴力即可

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    while (q--) {
        int l, r;
        cin >> l >> r;
        LL ans = 1;
        for (int i = l + 1; i <= r; i++) {
            if (a[i] >= a[l]) {
                ans++;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

jjgg的难题

根据题意的模拟,发现f最后的值就是n%p+(n/p)%p+((n/p)/p)%p...,发现当n<s的时候,不可满足,当n=s的时候,输出n+1即可,当n>s的时候,容易想到结果不会太大,可以根号暴力模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    LL n, s;
    cin >> n >> s;
    if (n < s) {
        cout << "-1\n";
        exit(0);
    }
    if (n == s) {
        cout << n + 1 << '\n';
        exit(0);
    }
    LL ans = 1999999999999LL;
    LL p = n - s;
    function<LL(LL)> check = [&](LL z) {
        z++;
        LL sum = 0, x = n;
        while (x) {
            sum += x % z;
            x /= z;
        }
        return sum;
    };
    for (LL i = 1; i * i <= p; i++) {
        if (p % i == 0) {
            if (check(i) == s) {
                ans = min(ans, i + 1);
            }
            if (check(p / i) == s) {
                ans = min(ans, p / i + 1);
            }
        }
    }
    if (ans != 1999999999999LL) {
        cout << ans << '\n';
    } else {
        cout << "-1\n";
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值