8.26-河西校区

· · 个人记录

8.26-河西校区

::::::info[T1]{open}

U593075 来追梦运动会之慢跑赛

::::info[思路] 模拟或者利用公式推导。 :::: ::::success[赛时代码&分数]

\color{green}{Accepted\not100pts}
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a, b, c, d, e, f, g;
int ls, qs, lt, qt, lv, qv;
bool lr = 1, qr = 1;
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> a >> b >> c >> d >> e >> f >> g;
    for (int i = 1; i <= g; i ++) {
        if (lr) {
            lt ++;
            if (lt == a) 
                lr = 0;
        } else {
            ls ++;
            if (ls == c) 
                lr = 1;
        }
        if (qr) {
            qt ++;
            if (qt == d) 
                qr = 0;
        } else {
            qs ++;
            if (qs == f) 
                qr = 1;
        }
    }
    lv = lt * b;
    qv = qt * e;
    cout << (lv == qv ? "Draw" : (lv < qv ? "Aoki" : "Takahashi"));
    return 0;
}
::::

::::::info[T2]{open}

T642548 引爆炸弹

::::info[思路] 主函数中对于每个未引爆的炸弹, dfs 枚举炸弹的行和列,若是新的炸弹则递归下去。在主函数冲记录每一次引爆炸弹的次数 :::: ::::warning[赛时分数]

\color{red}{Unaccepted\not0pts}

:::: ::::success[正解]

#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, ans;
char a[N][N];
void dfs(int x, int y) {
    for (int j = 1; j <= m; j ++) 
        if (a[x][j] == '1') {
            a[x][j] = '0';
            dfs(x, j);
        }
    for (int i = 1; i <= n; i ++) 
        if (a[i][y] == '1') {
            a[i][y] = '0';
            dfs(i, y);

        }
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) 
        for (int j = 1; j <= m; j ++) 
            cin >> a[i][j];
    for (int i = 1; i <= n; i ++) 
        for (int j = 1; j <= m; j ++) 
            if (a[i][j] == '1') {
                a[i][j] = '0';
                dfs(i, j);
                ans ++;
            }
    cout << ans;
    return 0;
}
::::

::::::info[T3]{open}

T642551 卡牌

::::info[思路] 用 map 当作桶来存储数字,再循环递增,具体见注释 :::: ::::warning[赛时得分]

\color{red}{Unaccepted\not0pts}

:::: ::::success[正解]

#include <bits/stdc++.h>
#define deb(x) cerr << #x << "=" << x << "\n";
using namespace std;
const int N = 2e5 + 5;
int t, n, x;
map<int, int> mp;
void sol() {
    int cnt = 0;
    mp.clear(); // 清空
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> x;
        mp[x] ++;
    }
    while (mp.size()) {
        cnt ++;
        for (auto f : mp) {
            x = f.first; // 获取第一个键-值对
            break;
        }
        mp[x] --;
        if (mp[x] == 0) 
            mp.erase(x); // 变成0就给它踢出去
        while (1) {
            x ++;
            if (mp.count(x) == 0) 
                break; // 没有这个数字,于是乎接不上了
            mp[x] --;
            if (mp[x] == 0) 
                mp.erase(x); // 变成0就给它踢出去
        }
    } 
    cout << cnt << "\n";
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t --) 
        sol();
    return 0;
}
::::

::::::info[T4]{open}

T643724 落落的去去扫雷

::::info[思路] 通过辅助数组设 b_1,b_2 初始值,推导得出 :::: ::::warning[赛时得分]

\color{red}{Unaccepted\not40pts}

:::: ::::success[正解]

#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, ans;
int a[N], b[N];
int check() {
    for (int i = 1; i <= n; i ++) {
        b[i + 1]= a[i] - b[i] - b[i - 1];
        if (b[i + 1] < 0 || b[i + 1] > 1) 
            return 0;
    }
    if (b[n + 1]) 
        return 0;
    return 1;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n; 
    for (int i = 1; i <= n; i ++) 
        cin >> a[i];
    if (a[1] == 0) 
        ans += check();
    else if (a[1] == 1) {
        b[1] = 1;
        ans += check();
        memset(b, 0, sizeof(b));
        b[2] = 1;
        ans += check();
    } else {
        b[1] = b[2] = 1;
        ans += check();
    }
    cout << ans;
    return 0;
}
::::

::::::info[T5]{open}

U592947 落落的去的数学问题4

::::info[思路] DP + 步步取模 :::: ::::warning[赛时得分]

\color{red}{Unaccepted\not40pts}

:::: ::::success[正解]

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, mod = 998244353;
int dp[N][10];
int n, ans;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= 9; i ++) 
        dp[1][i] = 1;
    for (int i = 2; i <= n; i ++) 
        for (int j = 1; j <= 9; j ++) {
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            if (j > 1) 
                dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
            if (j < 9) 
                dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % mod;
        }
    for (int i = 1; i <= 9; i ++) 
        ans = (dp[n][i] + ans) % mod;
    cout << ans;
    return 0;
}
::::