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

AtCoder Beginner Contest 322

时间:2023-11-26 17:55:54浏览次数:35  
标签:AtCoder Beginner int auto cin long 322 ++ using

A - First ABC 2

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define mp make_pair

using vi = vector<int>;
using pii = pair<int, int>;


void solve() {
    int n;
    string s;
    cin >> n >> s;
    auto it = s.find("ABC");
    if( it >= n ) cout << "-1\n";
    else cout << it + 1 << "\n";
    return ;
}


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();

    return 0;
}

B - Prefix and Suffix

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define mp make_pair

using vi = vector<int>;
using pii = pair<int, int>;


void solve() {
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == t[i]) continue;
        ans += 2;
        break;
    }
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    for (int i = 0; i < n; i++) {
        if (s[i] == t[i]) continue;
        ans += 1;
        break;
    }
    cout << ans << "\n";
    return;
}


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();

    return 0;
}

C - Festival

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define mp make_pair

using vi = vector<int>;
using pii = pair<int, int>;


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vi a(m);
    for (auto &i: a) cin >> i;
    reverse(a.begin(), a.end());
    for( int i = 1 ; i <= n ; i ++ ){
        cout << a.back() - i << "\n";
        if( a.back() == i ) a.pop_back();
    }
    return 0;
}

D - Polyomino

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define mp make_pair

using vi = vector<int>;
using pii = pair<int, int>;
using node = array<string, 4>;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    vector<node> g(3);
    int cnt = 0;
    for (auto &it: g)
        for (auto &i: it) {
            cin >> i;
            cnt += count(i.begin(), i.end(), '#');
        }
    auto rotate = [](const node &a) {
        auto b = a;
        for (int i = 0; i < 4; i++)
            for (int j = 0; j < 4; j++)
                b[j][3 - i] = a[i][j];
        return b;
    };
    array<array<char, 4>, 4> page;
    auto fit = [&](int k, int x, int y) {
        for (int i = 0, nx = x; i < 4; i++, nx++)
            for (int j = 0, ny = y; j < 4; j++, ny++) {
                if (g[k][i][j] == '.') continue;
                if (nx < 0 or nx > 3 or ny < 0 or ny > 3) return false;
                if (page[nx][ny] == '#') return false;
                page[nx][ny] = '#';
            }
        return true;
    };
    auto dfs = [&](auto &&self, int i) -> bool {
        if (i == 3) return true;
        auto bak = page;
        for (int x = -3; x <= 7; x++)
            for (int y = -3; y <= 7; y++) {
                for (int t = 0; t < 4; t++) {
                    if (fit(i, x, y) and self(self, i + 1))
                        return true;
                    g[i] = rotate(g[i]), page = bak;
                }
            }
        return false;
    };
    if (cnt == 16 and dfs(dfs, 0))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

E - Product Development

相对来说是一个比较板的 01 背包问题,只是状态的表示比较麻烦,所以可以状压一下。

#include<bits/stdc++.h>

using namespace std;

#define int long long

using i32 = int32_t;
using vi = vector<int>;

const int inf = 1e18;

i32 main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k, p;
    cin >> n >> k >> p;
    int base = p + 1;
    const int N = (int) (pow(base, k));
    vi f(N , inf);
    f[0] = 0;
    auto dtr = [k, base](int x) {
        vi ret(k);
        for (int i = k - 1; i >= 0; i--)
            ret[i] = x % base, x /= base;
        return ret;
    };
    auto tr = [k, base](const vi &x) {
        int res = 0;
        for (int i = 0; i < k; i++) res = res * base + x[i];
        return res;
    };
    for (int i = 0, c; i < n; i++) {
        cin >> c;
        vi a(k);
        for (auto &j: a) cin >> j;
        auto g = f;
        for (int i = 0; i < N; i++) {
            auto lst = dtr(i);
            for (int j = 0; j < k; j++)
                lst[j] = min(p, lst[j] + a[j]);
            auto nxt = tr(lst);
            g[nxt] = min(g[nxt], f[i] + c);
        }
        f.swap(g);
    }
    if (f.back() == inf) cout << "-1\n";
    else cout << f.back() << "\n";
    return 0;
}

标签:AtCoder,Beginner,int,auto,cin,long,322,++,using
From: https://www.cnblogs.com/PHarr/p/17857613.html

相关文章

  • 2023-2024-1 20232322 《#2023-2024-1 20232314杨红星《网络》第三周学习总结
    教材学习内容总结 教材学习中的问题和解决过程问题:如何防范安全攻击解决方案:通过查询得知 对于黑客一是及时更新服务器系统安全漏洞补丁二是要加强服务器安全防护能力三是制定有效的风险预警机制,重要数据一定要备份四是发现被“黑客”入侵时,要立即断网,保存好现场的犯罪......
  • AtCoder 329. E - Stamp (搜索 + 思维
    importjava.util.Scanner;classMain{staticintn,m;staticStrings,t;staticStringBuilderox;/***思路:*思路的大门:题目要要求把x变成s,我们可以反过来,把s变成只有#的x,所以我们就有了思路*1.从前......
  • TOYOTA SYSTEMS Programming Contest 2023(AtCoder Beginner Contest 330)
    TOYOTASYSTEMSProgrammingContest2023(AtCoderBeginnerContest330)A-CountingPassesintmain(){IOS;cin>>n>>m;intans=0;rep(i,1,n)cin>>k,ans+=k>=m;cout<<ans;return0;}B-......
  • AtCoder Beginner Contest 330
    A-CountingPasses(abc330A)题目大意给定\(n\)个学生的分数,以及及格分\(x\),问多少人及格了。解题思路依次判断即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_stdio(false);cin.ti......
  • AtCoder Beginner Contest 329 F
    AtCoderBeginnerContest329FF-ColoredBall(atcoder.jp)(启发式合并)问题陈述有\(N\)个编号为\(1,2,\ldots,N\)的盒子。最初,盒子\(i\)中有一个颜色为\(C_i\)的小球。给你\(Q\)个查询,你要按顺序处理。每个查询都由一对整数\((a,b)\)给出,并要求您执行以下......
  • AtCoder Regular Contest 144 E GCD of Path Weights
    洛谷传送门AtCoder传送门喵喵题。考虑若所有点权都已确定,如何求\(1\)到\(n\)所有路径权值和的\(\gcd\)。考虑如何check一个\(x\)是否合法。\(x\)合法的充要条件是,把不能从\(1\)到达的点和不能到达\(n\)的点扔掉后,存在一组\(\{f_n\}\),使得对于每条\(u\tov\)......
  • [AtCoder Toyota2023 Spring Final] Git Gud
    拜谢MagicDuck大神。其次我很喜欢洛谷逆天翻译把大翻译成小……首先考虑算一下贡献,考虑每个点的深度,一开始都是1,进行合并以后相当于首先把两个端点的深度累计到答案里,然后再选择一边给它的联通块内每个点深度增加1。那么容易发现我们可以算贡献转化为每个联通块权值为它向外......
  • AtCoder Beginner Contest 329
    劳累一天不该写题,启发式合并都写错了A-Spread(abc329A)题目大意给定一个字符串,将每个字符输出出来,中间留个空格。解题思路遍历输出即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_std......
  • AtCoder Beginner Contest(abc) 326
    B-326-likeNumbers难度:⭐题目大意如果一个三位数的百位和十位的乘积等于个位,那么这个数就是合法的;问大于等于n的最小的合法的数是多少;解题思路因为数据范围很小,所以可以直接暴力;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios......
  • AtCoder Beginner Contest 329
    C-Countxxx题意是:给你一个字符串,求出字符串里面相同字母的子串数量思路:用map映射即可,取每个字母的最大长度,然后加起来usingnamespacestd;intmain(){ intn; strings; cin>>n>>s; map<char,int>mp; intct=1; for(inti=1;i<n;i++){ if(s[i]!=s[i-1]){ mp[s[......