zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 180 个人题解(快乐DP场)

    补题链接:Here

    A - box

    输出 (N - A + B)

    B - Various distances

    按题意输出 3 种距离即可

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int N;
        ll x;
        ll ans1 = 0, ans2 = 0, ans3 = 0;
        cin >> N;
        for (int i = 0; i < N; i++) {
            cin >> x;
            ans1 += abs(x);
            ans2 += x * x;
            ans3 = max(ans3, abs(x));
        }
        double ans2_ = sqrt(double(ans2));
        cout << ans1 << endl;
        cout << fixed << setprecision(20) << ans2_ << endl;
        cout << ans3 << endl;
    }
    

    C - Cream puff

    set 容器存因子,然后循环输出

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        ll x, y, a, b;
        cin >> x >> y >> a >> b;
        ll ans = 0;
        while ((a - 1) * x <= b && a * x < y && (double)a * x <= 2e18) {
            x *= a, ans++;
        }
        cout << ans + (y - 1 - x) / b << '
    ';
        return 0;
    }
    

    D - Takahashi Unevolved

    题意:Iroha 在游戏中有一只宠物加 Takahashi,为了帮助 Takahashi 变得强力起来,需要将它送入训练场

    • Kakomon Gym:(STR imes= A,EXP += 1)
    • AtCoder Gym:(STR += B,EXP += 1)

    但是 STR 不能超过 Y 的情况下求 EXP 的最大值

    思路:最大化去第一种 Gym 的次数然后用 Y减去差值除 B 即可

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        ll x, y, a, b;
        cin >> x >> y >> a >> b;
        ll ans = 0;
        while ((a - 1) * x <= b && a * x < y && (double)a * x <= 2e18) {
            x *= a, ans++;
        }
        cout << ans + (y - 1 - x) / b << '
    ';
        return 0;
    }
    

    E - Traveling Salesman among Aerial Cities

    https://blog.csdn.net/weixin_45750972/article/details/109144617

    题意:给定边权的计算方法,求n nn个结点的最小曼哈顿回路花费。

    思路:状压DP

    (dp(i,j))为状态 (i) 下从起点出发到 (j) 的最小花费,这里的状态 (i) 指从起点要经过的城市

    最后答案即为:(dp[(1<<n)−1][0]),假设起点为 (0)

    状态方程:(dp[i][j]=min(dp[i][j],dp[i−(1<<j)][k]+dis(k,j)),(i&(1<<j)>0))

    #include <bits/stdc++.h>
    using namespace std;
    using ll    = long long;
    const int N = 17, M = (1 << 17) + 1;
    int n, x[N], y[N], z[N];
    ll dp[M][N];
    ll d(int a, int b) {
        return abs(x[a] - x[b]) + abs(y[a] - y[b]) + max(0, z[b] - z[a]);
    }
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        cin >> n;
        for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> z[i];
        memset(dp, 0x3f, sizeof(dp));
        dp[0][0] = 0;
        for (int i = 1; i < (1 << n); ++i) {
            for (int j = 0; j < n; ++j)
                if ((i >> j) & 1)
                    for (int k = 0; k < n; ++k)
                        dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + d(k, j));
        }
        cout << dp[(1 << n) - 1][0] << '
    ';
        return 0;
    }
    

    F - Unbranched

    官方题解:https://atcoder.jp/contests/abc180/editorial/250

    这里做的有点懵,贴一下代码

    这里使用了 atcoder/all 头文件,添加方法:Click Here

    #include <atcoder/all>
    using mint = atcoder::modint1000000007;
    int N, M, L;
    mint f(int L) {
        mint dp[303][303];
        dp[0][0] = 1;
        for (int i = 0; i < N; i++)
            for (int j = 0; j <= i; j++) {
                mint T = dp[i][j];
                for (int k = 1; i + k <= N && j + k - 1 <= M && k <= L; k++) {
                    if (k > 1) dp[i + k][j + k] += T;
                    if (k == 2) T *= 500000004;
                    dp[i + k][j + k - 1] += T * k;
                    T *= N - i - k;
                }
            }
        return dp[N][M];
    }
    int main() {
        std::cin >> N >> M >> L;
        std::cout << (f(L) - f(L - 1)).val();
        return 0;
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    AJAX问题总结(针对JAVA)
    关于IE浏览器的缓存问题
    tomcat和jdk版本兼容问题。
    Java中的索引和数据库的索引区别
    Eclipse 连接Oracle 11g 时报ORA-12505错误的解决办法
    Tomcat 8 & JNDI Datasource
    【LeetCode】019. Remove Nth Node From End of List
    【前端UI框架】EasyUI
    装饰者模式
    【LeetCode】234. Palindrome Linked List
  • 原文地址:https://www.cnblogs.com/RioTian/p/14607901.html
Copyright © 2011-2022 走看看