湖南理工学院2022年程序设计竞赛新生赛(12/14)

lwy梦境中的斐波那契数列——诈骗签到题

等差数列求和

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    LL n;
    cin >> n;
    cout << n * (n + 1) / 2 % 4399 << '\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 n;
    cin >> n;
    int ans = 0;
    vector<vector<int>> a(n + 1, vector<int> (n + 1));
    vector<vector<bool>> vis(n + 1, vector<bool> (n + 1));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[1][i]) {
            vis[1][i] = true;
            ans += a[1][i];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i][1]) {
            vis[i][1] = true;
            ans += a[i][1];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i][n]) {
            vis[i][n] = true;
            ans += a[i][n];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[n][i]) {
            vis[n][i] = true;
            ans += a[n][i];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i][i]) {
            vis[i][i] = true;
            ans += a[i][i];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i][n - i + 1]) {
            vis[i][n - i + 1] = true;
            ans += a[i][n - i + 1];
        }
    }
    cout << ans << '\n';
    return 0;
}

你还会想起这道题吗(another version)

模拟

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;
    LL ans = 0;
    vector<vector<int>> a(n + 1, vector<int> (n + 1));
    vector<vector<bool>> vis(n + 1, vector<bool> (n + 1));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }
    for (int k = 0; k <= (n + 1) / 2; k++) {
        LL sum = 0;
        for (int i = 1 + k; i <= n - k; i++) {
            if (!vis[1 + k][i]) {
                vis[1 + k][i] = true;
                sum += a[1 + k][i];
            }
        }
        for (int i = 1 + k; i <= n - k; i++) {
            if (!vis[i][1 + k]) {
                vis[i][1 + k] = true;
                sum += a[i][1 + k];
            }
        }
        for (int i = 1 + k; i <= n - k; i++) {
            if (!vis[i][n - k]) {
                vis[i][n - k] = true;
                sum += a[i][n - k];
            }
        }
        for (int i = 1; i <= n - k; i++) {
            if (!vis[n - k][i]) {
                vis[n - k][i] = true;
                sum += a[n - k][i];
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << '\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 n, m;
    cin >> n >> m;
    map<string, LL> mp;
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        int z;
        cin >> z;
        for (int j = 0; j < z; j++) {
            string s;
            int w;
            cin >> s >> w;
            mp[s] += w;
        }
    }
    for (int i = 0; i < m; i++) {
        string s;
        int w;
        cin >> s >> w;
        ans = ans + 1LL * mp[s] * w;
    }
    cout << ans << '\n';
    return 0;
}

一道较为复杂的签到题

不要被题意平均头发数误导,有一个光头乘积全为0

AC代码:

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

n车摆放问题

组合数学

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    cout << min(n, m) << '\n';
    LL res = 1;
    for (int i = 0; i < min(n, m); i++) {
        res = res * (max(n, m) - i);
    }
    cout << res << '\n';
    return 0;
}

皮卡丘的梦幻之旅(easy version)

皮卡丘的梦幻之旅(middle version)

DP

相当于有区别的n的m个划分,循环的时候把n和m遍历互换即可

相当于第m个划分用第n种方式

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mod = 998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> m >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> dp(m + 1);
    dp[0] = 1;
    for (int i = 0; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (i + a[j] <= m) {
                dp[i + a[j]] = (dp[i + a[j]] + dp[i]) % mod;
            }
        }
    }
    cout << dp[m] << '\n';
    return 0;
}

n个数的高精度乘法

取模运算性质

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mod = 10000;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    LL res = 1;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int len = s.size();
        string t = "";
        for (int i = len - 1; i > len - 1 - 4 and i >= 0; i--) {
            t += s[i];
        }
        reverse(t.begin(), t.end());
        LL z = stoll(t);
        res = res * z % mod;
    }
    cout << res << '\n';
    return 0;
}

轩哥的疑惑

AC代码:

14

集!挡!波!

除了第一个操作,可以一直等到他出J就能赢,否则平

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;
    string s;
    cin >> s;
    for (int i = 1; i < n; i++) {
        if (s[i] == 'J') {
            cout << "win\n";
            return 0;
        }
    }
    cout << "draw\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);
    LL n, k;
    cin >> n >> k;
    vector<LL> z;
    LL x = n;
    while (x) {
        z.push_back(x % k);
        x /= k;
    }
    LL ans = 0;
    int len = z.size();
    bool ok = true;
    for (int i = 0; i < len - 1; i++) {
        if (z[i] != k - 1) {
            ok = false;
            break;
        }
    }
    if (ok) {
        ans = len;
        for (int i = 0; i < len; i++) {
            ans += z[i];
        }
    } else {
        ans = len;
        LL p = 0;
        LL sum = len;
        for (int i = 0; i < len; i++) {
            sum += z[i];
        }
        for (int i = len - 1; i >= 0; i--) {
            if (z[i] != 0) {
                if (i == len - 1 and z[i] == 1) {
                    ans = max(ans, len - 1 + (len - 1) * (k - 1));
                } else {
                    ans = max(ans, z[i] - 1 + i * (k - 1) + len + p);
                }
            }
            p += z[i];
        }
        ans = max(ans, sum);
    }
    cout << ans << '\n';
    return 0;
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值