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

AtCoder Beginner Contest 289

时间:2023-02-12 01:56:41浏览次数:44  
标签:std AtCoder Beginner int cin long 289 ++ vector

A. flip

C++ Code
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::string s;
    std::cin >> s;

    for (auto &si : s) {
        si = '1' - si + '0';
    }

    std::cout << s << '\n';
    
    return 0;
}

B. V

C++ Code
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m;
    std::cin >> n >> m;

    std::vector<int> a(n);
    for (int i = 0; i < m; i++) {
        int x;
        std::cin >> x;
        x--;
        a[x] = 1;
    }

    int j = 0;
    for (int i = 0; i < n; i = j + 1) {
        j = i;
        while (j < n && a[j]) {
            j++;
        }

        for (int k = j; k >= i; k--) {
            std::cout << k + 1 << ' ';
        }
    }

    std::cout << '\n';
    
    return 0;
}

C. Coverage

枚举子集。

C++ Code
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m;
    std::cin >> n >> m;

    std::vector<int> a(m);
    for (int i = 0; i < m; i++) {
        int ci;
        std::cin >> ci;

        for (int j = 0; j < ci; j++) {
            int x;
            std::cin >> x;
            x--;
            a[i] |= 1 << x;
        }
    }

    int ans = 0;
    for (int j = 0; j < (1 << m); j++) {
        int res = 0;
        for (int i = 0; i < m; i++) {
            if (j >> i & 1) {
                res |= a[i];
            }
        }

        if (res == (1 << n) - 1) {
            ans++;
        }
    }

    std::cout << ans << '\n';

    return 0;
}

D. Step Up Robot

bfs。

C++ Code
#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 1E5;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    int m;
    std::cin >> m;

    std::vector<int> b(m);
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }

    int x;
    std::cin >> x;

    std::vector<bool> ban(N + 1);
    for (int i = 0; i < m; i++) {
        ban[b[i]] = 1;
    }

    std::vector<bool> vis(N + 1);
    std::queue<int> q;
    q.push(0);
    vis[0] = 1;

    while (!q.empty()) {
        int cur = q.front();
        q.pop();

        if (cur == x) {
            std::cout << "Yes\n";
            return 0;
        }

        for (int i = 0; i < n; i++) {
            int nex = cur + a[i];

            if (nex <= x && !vis[nex] && !ban[nex]) {
                q.push(nex);
                vis[nex] = 1;
            }
        }
    }

    std::cout << "No\n";
    
    return 0; 
}

E. Swap Places

模拟。\(ans_{ij}\) 表示 Takahashi 在 \(i+1\),Aoki 在 \(j+1\)。

C++ Code
#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> c(n);
    for (int i = 0; i < n; i++) {
        std::cin >> c[i];
    }

    std::vector<std::vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;

        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    std::vector<std::vector<int>> ans(n, std::vector<int>(n, -1));
    std::queue<std::array<int, 2>> q;

    q.push({0, n - 1});
    ans[0][n - 1] = 0;

    while (!q.empty()) {
        auto [x1, y1] = q.front();
        q.pop();
        for (auto x2 : adj[x1]) {
            for (auto y2 : adj[y1]) {
                if (c[x2] != c[y2] && ans[x2][y2] == -1) {
                    ans[x2][y2] = ans[x1][y1] + 1;
                    q.push({x2, y2});
                }
            }
        }
    }

    std::cout << ans[n - 1][0] << '\n';    
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0; 
}

F. Teleporter Takahashi

先考虑 No 的情况:

首先 \(|sx-tx|\) 为奇数或者 \(|sy-ty|\) 为奇数就肯定是 No。

只要借助 \((a,c),(a+1,c),(a,c+1)\) 这三个点进行操作就一定可以实现将 \(s\) 移动到 \(t\)。

考虑 \(a=c\) 或 \(c=d\)。

C++ Code
#include <bits/stdc++.h>

using i64 = long long;

using Point = std::pair<int, int>;

#define x first
#define y second

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int sx, sy, tx, ty, a, b, c, d;
    std::cin >> sx >> sy >> tx >> ty >> a >> b >> c >> d;

    Point s(sx, sy);
    Point t(tx, ty);

    if (std::abs(sx - tx) % 2 == 1 || std::abs(sy - ty) % 2 == 1) {
        std::cout << "No\n";
        return 0;
    }

    std::vector<Point> ans;
    auto R = [&](int x, int y) {
        ans.push_back(Point(x, y));
        return Point(2 * x - s.x, 2 * y - s.y);
    };

    if (a == b && s.x != t.x) {
        s = R(a, c);
    }

    if (c == d && s.y != t.y) {
        s = R(a, c);
    }

    if (a != b) {
        while (s.x < t.x) {
            s = R(a, c);
            s = R(a + 1, c);
        }

        while (s.x > t.x) {
            s = R(a + 1, c);
            s = R(a, c);
        }        
    }

    if (c != d) {
        while (s.y < t.y) {
            s = R(a, c);
            s = R(a, c + 1);
        }

        while (s.y > t.y) {
            s = R(a, c + 1);
            s = R(a, c);
        }         
    }

    if (s == t) {
        std::cout << "Yes\n";
        for (auto &[x, y] : ans) {
            std::cout << x << ' ' << y << '\n';
        }              
    } else {
        std::cout << "No\n";
    }

    return 0; 
}

标签:std,AtCoder,Beginner,int,cin,long,289,++,vector
From: https://www.cnblogs.com/kiddingma/p/17113173.html

相关文章

  • abc289g题解
    考虑枚举卖出的物品个数\(i\),把\(b_i\)从大到小排序。题目的某人会买物品的条件转化为\(b_i\geqp_j-c_j\),这说明卖出的物品的集合是排序后\(b\)的一段前缀,且卖出\(i\)个......
  • Atcoder Beginner Contest 289
    ContestResult做出了\(\texttt{A}\sim\texttt{F}\),\(\texttt{G}\)题有点思路,但时间不够了。\(\texttt{E}\)题状态设计太慢,复杂度其实也没算明白,\(\texttt{F}\)题......
  • AtCoder Beginner Contest 288
    E.WishList假设你需要选择\(B_1,B_2,..,B_k\)这\(K\)个元素编号。假设当前你选择\(B_i\)元素,且前面\(i-1\)个元素\(B_1,B_2,...,B_{i-1}\)选择了\(x\)个(\(......
  • AtCoder Beginner Contest 288
    《D-RangeAddQuery》题目大意:给定一个长度为n的序列s,和一个整数k我们可以对s进行无数次如下操作:1、选定s中的一个下标i(1<=i<=n-k+1)2.......
  • 没有终结点在侦听可以接受消息的http://192.168.9.31:5289/services/EBService
      原因:我方银行账号启用了支持网银,但未正确配置银企互联,需要取消,如下图: ......
  • AtCoder Beginner Contest 288
    A-ManyA+BProblems签到#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongint32_tmain(){intn;cin>>n;for(inta,b......
  • AtCoder Beginner Contest 288
    A-ManyA+BProblems(abc288a)题目大意给定\(A\),\(B\),输出\(A+B\)。解题思路范围不会爆\(int\),直接做即可。神奇的代码#include<bits/stdc++.h>usingname......
  • AtCoder Beginner Contest 235 G Gardens
    洛谷传送门考虑不要求每个盒子至少放一个球,答案即为\(\sum\limits_{i=0}^A\binom{n}{i}\times\sum\limits_{i=0}^B\binom{n}{i}\times\sum\limits_{i=0}^C\binom{......
  • AtCoder Beginner Contest 168 C - : (Colon)
    题意:时针转过的角度:​分针转过的角度:。AC代码:constintN=1e6+50;constdoublepi=acos(-1.0);intmain(){doublea,b,h,m;cin>>a>>b>>h>>m;lon......
  • AtCoder Beginner Contest 168 D - .. (Double Dots)
    题意:有个房间,在这些房间中两两连次条边,问除了第一个房间,其他房间走到第一个房间的最短路径,输出这个房间所连的上一个房间,如果走不到,输出.AC代码;constintN=......