首页 > 其他分享 >AtCoder Beginner Contest 134

AtCoder Beginner Contest 134

时间:2023-01-12 19:34:04浏览次数:65  
标签:std AtCoder main Beginner int cin 134 using include

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

标签:std,AtCoder,main,Beginner,int,cin,134,using,include
From: https://www.cnblogs.com/CTing/p/17047717.html

相关文章

  • AtCoder Beginner Contest 042
    A-IrohaandHaiku(ABCEdition)#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){inta=2,b=1;for(inti=1,x;i<=3;i++......
  • AtCoder Beginner Contest 133
    AtCoderBeginnerContest133https://atcoder.jp/contests/abc133A-TorT#include<bits/stdc++.h>usingnamespacestd;intmain(){inta,b,n;ci......
  • AtCoder Beginner Contest 171
    A-αlphabet(abc171a)题目大意给定一个字母,其大写字母则输出A,否则输出a。解题思路isupper函数或者在'A'与Z之间即为大写字母。神奇的代码#include<bits/stdc+......
  • AtCoder284 D - Happy New Year 2023
    AtCoder284D-HappyNewYear2023[Editorial](Editorial-AtCoderBeginnerContest284)Youaregivenapositiveinteger\(N\).Itisknownthat\(N\)canbe......
  • AtCoder Beginner Contest 284
    A-SequenceofStrings#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){intn;cin>>n;vector<string>s(n);for(auto&i:s)......
  • Atcoder ABC112D Partition
    链接难度:\(\texttt{1025}\)找到最大的正整数\(x\)使得\(m\modx=0\)且\(\frac{m}{x}\gen\)。难度在于读题,简化后就简单的一批了。暴力都能过。枚举\(m\)的......
  • AtCoder Beginner Contest 284(D,E,F)
    AtCoderBeginnerContest284(D,E,F)DD这可题的大意是有一个很大的数,n,它可以变成pXpXq(p,q是质数),要我们找出这两个质数我们可以发现,这一个n的质因数一定只有两个,p,q,而我......
  • C - Count Connected Components -- ATCODER
    C-CountConnectedComponentshttps://atcoder.jp/contests/abc284/tasks/abc284_c 思路寻找独立的子连通图个数。 使用map记录边,即点之间的连通性使用vector记......
  • AtCoder Beginner Contest 284
    AtCoderBeginnerContest284https://atcoder.jp/contests/abc284被D卡了,感觉十分的弱智。GEx看不懂题解(A-SequenceofStrings#include<bits/stdc++.h>usingn......
  • AtCoder Beginner Contest 284 C - Count Connected Components DFS的应用
    TimeLimit:2sec/MemoryLimit:1024MBScore: 300300 pointsProblemStatementYouaregivenasimpleundirectedgraphwith NN verticesnumbered 11 ......