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

AtCoder Beginner Contest 314

时间:2023-08-14 16:36:21浏览次数:40  
标签:AtCoder cout Beginner get int auto cin 314 map

AtCoder Beginner Contest 314 - AtCoder

A 3.14

void solve() {
    string s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
    int n;
    cin >> n;
    cout << s.substr(0,n + 2) << endl;
}

B Roulette

题意:给有个\(x\),输出以下给的\(n\)个数组里包含\(x\)的数组(里面元素最少的),如果有多个,按升序输出

思路:先统计有\(x\)的数组,有\(map\)存下来,并且实时更新数组最小的,把map里的键值取出来放到结构体里按编号排序

struct S {
    int id;
    vector<int> a;
};

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> a(n);
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        while (m--) {
            int x;
            cin >> x;
            a[i].push_back(x);
        }
    }
    int k;
    cin >> k;
    map<int, vector<int>> mp;
    int mn = INT_MAX;
    for (int i = 0; i < n; i++) {
        bool ok = false;
        for (auto j : a[i]) {
            if (j == k)ok = true;
        }
        if (ok) {
            mn = min(mn, (int) a[i].size());

            for (auto j : a[i]) {
                mp[i].push_back(j);
            }
        }
    }
    vector<S> ans;
    //    cout << mn << endl;
    for (auto [x1, x2] : mp) {
        //        cout << x1 << ' ' << x2.size() << endl;
        if (x2.size() == mn) {
            ans.push_back({x1, x2});
        }
    }
    sort(ALL(ans), [](S x1, S x2) {
        return x1.id < x2.id;
    });
    cout << ans.size() << endl;
    for (auto [x, y] : ans)cout << x + 1 << ' ';
    cout << endl;
}

C Rotate Colored Subsequence

题意:给一个数组\(a\)和字符串\(S\),下标一一对应,\(a[i]\)相同的下标所对应的字符组成一个字符串往右移动移动一位,最后再把变换后的还原

思路:用\(map\)来存\(a[i]\)相同的字符串,在把\(map\)存的的字符串按规则变换,最后根据数组\(a\)把对应的字符输出

void solve() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> a(n);
    for(auto &i : a)cin >> i;
    map<int, string> mp;
    for(int i = 0; i < n; i++) {
        mp[a[i]] += s[i];
    }
    for(auto &[x, y] : mp) {
        char op = y.back();
        y.pop_back();
        y = op + y;
        reverse(ALL(y));
    }
    for(auto i : a) {
        cout << mp[i].back();
        mp[i].pop_back();
    }
    cout << endl;
}

D LOWER

题意:给一个字符串\(S\),给q次询问,每次询问给\(t\),\(x\),\(c\),根据规则堆字符串进行变换

  • 如果 \(t _ i=1\), 将 \(S\) 中的 \(x _ i\)/th 字符改为 \(c _ i\)。

  • 如果 \(t _ i=2\), 将 \(S\) 中的所有大写字母转换为小写字母(在此操作中不要使用 \(x _ i,c _ i\))。

  • 如果 \(t _ i=3\) ,将 \(S\) 中的所有小写字母转换为大写字母(此操作不要使用 \(x _ i,c _ i\))。

思路:可以发现只有最后一个改变大小写(不为1)的询问会决定最终整个字符串的大小写,而在这之后如果还有修改(\(t\)为1)询问,还要再次修改字符串,我们找到最后一个\(t\)不为\(1\)的位置,先把这个位置,在改变大小写,再改变后面\(t\)为\(1\)的询问修改,最后输出

int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<T > b;
    while (q--) {
        int t, x;
        char c;
        cin >> t >> x >> c;
        // if (t == 1)s[x - 1] = c;
        b.push_back({t, x, c});
    }
    // cout<<b.size()<<endl;
    int pos = INT_MAX;
    int ret = 0;
    for (int i = b.size() - 1; i >= 0; i--) {
        if (get<0>(b[i]) != 1) {
            if(get<0>(b[i]) == 2)ret = 2;
            else ret = 3;
            break;
        } else pos = i;
    }
    for(int i = 0; i < n; i++) {
        if(get<0>(b[i]) == 1)s[get<1>(b[i]) - 1] = get<2>(b[i]);
    }
    if (ret == 2)for (auto &j : s)j = (char) tolower(j);
    else if(ret == 3)for (auto &j : s)j = (char) toupper(j);

    // else pos=i;

    //    cout<<pos<<endl;

    for (int i = pos; i < b.size(); i++) {
        s[get<1>(b[i]) - 1] = get<2>(b[i]);
    }
    cout << s << endl;

标签:AtCoder,cout,Beginner,get,int,auto,cin,314,map
From: https://www.cnblogs.com/north-h/p/17629036.html

相关文章

  • AtCoder Beginner Contest 314 A - Ex题解
    AtCoderBeginnerContest314A-3.14嗯,你可以用string存小数点后的...B-Roulette对于每一个金额,用个vector存pair<>存一个人赌了多少,以及是哪一个人。C-RotateColoredSubsequence每种数用个双向链表记下来。D-LOWER我们观察到,对于2,3操作,只有最后一次有用,且......
  • ABC 314 G
    简单题,但是我赛时没写完,少了一个\(5\)分钟。link程序有点丑,就不放link了,去掉注释在这。code#include<bits/stdc++.h>usingnamespacestd;#definede(x)cout<<#x<<"="<<x<<endlusingll=longlong;constintN=6e5+5;lln,m,h,a[N],b[N]......
  • ABC 314 F 题解
    原题传送门题意有n支队伍进行比赛,起初,第i支队伍只有选手i一个人。总共要进行n-1场比赛,每次给出p和q,意为让p所在的队伍与q所在的队伍进行比赛(数据保证此时p和q不在同一支队伍),设p所在的队伍有\(siz_p\)个人,q所在的队伍有\(siz_q\)个人,则此次比赛中p......
  • ABC314
    T1:3.14模拟代码实现s='3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'n=int(input())ans=s[0:n+2]print(ans)T2:Roulette模拟代码实现#include<bits/stdc++.h>#definerep(i,n)for......
  • AtCoder Beginner Contest 214
    AtCoderBeginnerContest214-AtCoder [ABC214D]SumofMaximumWeights ------------------------------(典)题意:给出一颗N-1 条边的树,求树上任意两点间路径上的最大值的和这种问题考虑每条边单独看贡献,但是刚开始没太想明白怎么计算贡献,后面看了洛谷题解才懂了-......
  • Atcoder杂题笔记
    大概会把博客当草稿纸用(当然写出正解还是会把正解贴出来。[ARC080E]YoungMaids(待补代码)给定正偶数\(N\)。给定\(N\)元排列\(p=(p_1,p_2,...,p_N)\).Snuke打算根据下述步骤构造一个\(N\)元排列\(q\)。首先,令\(q\)为空。接下来,执行下述操作直到\(p\)为空......
  • Atcoder ABC307_G-Approximate Equalization 序列dp
    AT_ABC307_G-ApproximateEqualization没想到还有ApproximateEqualizationII!!:AT_ABC313_CDescription:给定一个长度为\(N\)的数列:\(A=(A_1,A_2,···,A_N)\),有两种操作可以以任意顺序进行任意多次(可以为0):\(A[i]-\)=\(1\)且\(A[i+1]+\)=\(1\),\((1\leqi\leqN-1)......
  • AtCoder-ARC073_A Sentou
    Sentou【题意】:有一个开关,当按下开关后的T秒内会一直放水,当在放水状态时,如果有人再次按下开关,那么停止放水,并从按下的那一刻起的T秒会再次一直放水,给出n个人按压开关的时间,问总共流出多少水【思路】:简单模拟#include<bits/stdc++.h>usingnamespacestd;typedeflon......
  • AtCoder Beginner Contest 313
    AtCoderBeginnerContest313A-ToBeSaikyo思路:找到最大的,和第一个比较#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpair<int,int>PII;typedefpair<string,int>PSI;t......
  • AtCoder Beginner Contest 313
    AtCoderBeginnerContest313-AtCoderA-ToBeSaikyo(atcoder.jp)从\(a_1\dotsa_{n-1}\)找出最大值与\(a_0\)比较即可#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;signedmain(){ios::sync_with_st......