其他分享
首页 > 其他分享> > LINE Verda Programming Contest(AtCoder Beginner Contest 263)A-E

LINE Verda Programming Contest(AtCoder Beginner Contest 263)A-E

作者:互联网

LINE Verda Programming Contest(AtCoder Beginner Contest 263)

https://atcoder.jp/contests/abc263
F G 待补

A - Full House

输入5个数,判断是否满足两个数相等,另外三个数相等

#include <bits/stdc++.h>

using namespace std;

int main () {
    set<int> s;
    map<int, int> mp;
    int n = 5, x;
    while (n --) {
        cin >> x;
        s.insert(x);
        mp[x] ++;
    }
    
    if (mp.size() != 2) {
        cout << "No";
        return 0;
    }
    bool f1 = false, f2 = false;
    for (auto i : mp) {
        if (i.second == 2)  f1 = true;
        if (i.second == 3)  f2 = true;
    }
    if (f1 && f2) {
        cout << "Yes";
    }
    else    cout << "No";
}

B - Ancestor

找爸爸:i的爸爸是pi,问n和1之间隔了几代
挨个找过去即可

#include <bits/stdc++.h>

using namespace std;
const int N = 55;
int a[N], n;

int main () {
    cin >> n;
    for (int i = 2; i <= n; i ++)   cin >> a[i];
    int ans = 0, x = n;
    while (1) {
        x = a[x];
        ans ++;
        if (x == 1) break;
    }
    cout << ans;
}

C - Monotonically Increasing

输出所有长度为n,可选数范围为1-m的严格上升序列
全排列 + 筛选

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a;
    for (int i = 0; i < n; i++)
        a.push_back(0);
    for (int i = 0; i < m - n; i++)
        a.push_back(1);
    for (int i = 0; i < m; i++)
            if (a[i] == 0)
                cout << i + 1 << " ";
        cout << endl;

    while (next_permutation(a.begin(), a.end())) {
        for (int i = 0; i < m; i++)
            if (a[i] == 0)
                cout << i + 1 << " ";
        cout << endl;
    }
}

//输出所有长度为2,数字范围在1~m的严格上升序列

D - Left Right Operation

题意

进行如下操作各一次:

  1. 把 \(a_1,a_2,...,a_x\) 全替换为 L;
  2. 把 \(a_{n-y+1},...,a_{n-1},a_n\) 全替换为 R;

\(0\leq x,y\leq n\)
问a的和最小为多少

分析

f1[i]表示1i最小可能和,f2[i]表示in最小可能和
则答案在f1[i]+f2[i+1]中取(尽可能替换更多的,故枚举分界点)

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

using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 5, inf = 1e18;
int n, a[N], l, r;
int f1[N], f2[N];

signed main () {
    cin >> n >> l >> r;
    for (int i = 0; i < n; i ++)   cin >> a[i];

    f1[0] = min (a[0], l), f2[n-1] = min (a[n-1], r);
    for (int i = 1; i < n; i ++) 
        f1[i] = min (f1[i-1] + a[i], l*(i+1));
    for (int i = n-2; i >= 0; i --) 
        f2[i] = min (f2[i+1] + a[i], r*(n-i));

    int ans = min (f2[0], f1[n-1]);
    for (int i = 0; i < n-1; i ++)   ans = min (ans, f1[i]+f2[i+1]);
    
    cout << ans << endl;
    
    
}
//把前x全变成L,或把后y全变成R
//只能各操作一次

E - Sugoroku 3

题意

1n-1每个上都有一个骰子

标签:AtCoder,f2,Beginner,Contest,int,f1,++,ans,mod
来源: https://www.cnblogs.com/CTing/p/16558563.html