AtCoder Beginner Contest 134

AtCoder Beginner Contest 134

https://atcoder.jp/contests/abc134

A - Dodecagon

#include <bits/stdc++.h>

using namespace std;

int main () {
    int a;
    cin >> a;
    cout << 3 * a * a;
}

B - Golden Apple

#include <bits/stdc++.h>

using namespace std;

int main () {
    int n, d;
    cin >> n >> d;
    cout << (n + 2 * d) / (2 * d + 1);
}

C - Exception Handling

#include <bits/stdc++.h>

using namespace std;
map<int, int>mp;
vector<int> v;

int main () {
    int n, maxn = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;  cin >> x;
        maxn = max (maxn, x);
        mp[x] ++;
        v.push_back (x);
    }
    if (mp[maxn] > 1) {
        while (n --)    cout << maxn << endl;
        return 0;
    }

    int maxx = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == maxn)   continue;
        maxx = max (maxx, v[i]);
    }

    for (int i = 0; i < n; i++) {
        if (maxn == v[i])   cout << maxx << endl;
        else    cout << maxn << endl;
    }
}

D - Preparing Boxes

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int a[N], b[N], n, cnt;

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    for (int i = n; i >= 1; i--) {
        for (int j = i + i; j <= n; j += i)    b[i] += b[j];
        b[i] %= 2;
        if (b[i] != a[i])  cnt ++, b[i] = 1;
        else    b[i] = 0;
    }
    cout << cnt << endl;
    for (int i = 1; i <= n; i++) {
        if (b[i])   cout << i << ' ';
    }
}

//暴力
//倒序找,统计倍数下标和,如果不相等就要补1

E - Sequence Decomposing

#include <bits/stdc++.h>

using namespace std;

int main () {
    vector<int> a;
    int n, x;  cin >> n;
    for (int i = 0; i < n; i++)    cin >> x, a.push_back (x);
    multiset <int> s; //维护这若干个序列的结尾
    for (int i = 0; i < n; i++) { //每次接在最小的小于ai的数字后面
        auto it = s.lower_bound (a[i]);
        if (it == s.begin ())   s.insert (a[i]); //新开一个
        else    s.erase (prev(it)), s.insert (a[i]); //修改结尾
    }
    cout << s.size ();
}

//最少不相交上升序列
//每次接在最小的结尾就能接更多的数字

F - Permutation Oddness

妙妙dp:https://www.luogu.com.cn/blog/TanWeiYe/solution-at4823

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 55, mod = 1e9 + 7;
int n, m, f[N][N][N*N]; //f[i][j][k]: 考虑到前i个数,还有j个没有配对,怪异值为k

signed main () {
    cin >> n >> m;
    f[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 2 * j; k <= m; k += 2) {
                int f1, f2, f3 = 0;
                f1 = (f[i-1][j+1][k-j*2] * (j + 1) % mod * (j + 1) % mod) % mod; //配对了2个
                f2 = (f[i-1][j][k-j*2] * (2 * j + 1) % mod) % mod; //配对了1个
                if (j) f3 = (f[i-1][j-1][k-j*2]) % mod; //配对了0个
                (f[i][j][k] += f1 + f2 + f3) %= mod;
            }
        }
    }
    cout << f[n][0][m] << endl;
}


//难想的一道dp
posted @ 2023-01-12 19:16  Sakana~  阅读(20)  评论(0编辑  收藏  举报