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

Atcoder Beginner Contest 289

时间:2023-02-11 21:58:35浏览次数:41  
标签:Atcoder sy sx Beginner int 289 dx dy push

Contest Result

做出了 \(\texttt{A} \sim \texttt{F}\),\(\texttt{G}\) 题有点思路,但时间不够了。

\(\texttt{E}\) 题状态设计太慢,复杂度其实也没算明白,\(\texttt{F}\) 题大思路来的很快,但被 \(a=b \and c=d\) 的 Corner Case 创飞了。

Solution

A flip

#include<bits/stdc++.h>
using namespace std;

char s[1000000];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    for(int i = 1; i <= n; i++) {
        if(s[i] == '0') putchar('1');
        else putchar('0');
    }
}

B V

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 100 + 7;

int N, M;
int a[MAXN];

vector <int> vec[MAXN];
int vis[MAXN];
int cnt;

void work(int x) {
    queue <int> Q;
    Q.push(x);
    vis[x] = x;
    while(Q.size()) {
        int y = Q.front();
        for(auto to : vec[y]) {
            if(vis[to]) continue;
            vis[to] = x;
            Q.push(to);
        }
        Q.pop();
    }
}
int main() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        cin >> a[i];
        vec[a[i]].push_back(a[i] + 1);
        vec[a[i] + 1].push_back(a[i]);
    }
    for(int i = 1; i <= N; i++) {
        if(vis[i]) continue;
        work(i);
        for(int j = N; j >= 1; j--) {
            if(vis[j] != i) continue;
            ++cnt;
            printf("%d%c", j, " \n"[cnt == N]);
        }
    }
}

C Coverage

#include<bits/stdc++.h>
using namespace std;

int N, M;
int a[20];

int main() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int K; cin >> K;
        for(int j = 1; j <= K; j++) {
            int x; cin >> x;
            a[i] |= (1 << (x - 1));
        }
    }
    int ans = 0;
    for(int p = 0; p < (1 << M); p++) {
        int status = 0;
        for(int i = 1; i <= M; i++) {
            if(((p >> (i - 1)) & 1) == 0) continue;
            status |= a[i];
        }
        if(status == ((1 << N) - 1)) ++ans;
    }
    cout << ans << endl;
}

D Step Up Robot

#include<bits/stdc++.h>
using namespace std;

const int MAXW = 100000 + 7;

bool trap[MAXW], f[MAXW];
int N, M, a[20], K;

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    cin >> M;
    for(int i = 1, x; i <= M; i++) {
        cin >> x;
        trap[x] = true;
    }
    f[0] = true;
    cin >> K;
    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= N; j++) {
            if(a[j] > i) continue;
            f[i] |= f[i - a[j]];
        }
        if(trap[i]) f[i] = false;
    }
    if(f[K]) puts("Yes");
    else puts("No");
    return 0;
}

E Swap Places

#include<bits/stdc++.h>
using namespace std;

int T;
const int MAXN = 2000 + 7;
const int INF = 0x3f3f3f3f;
vector <int> vec[MAXN];
int N, M;
int f[MAXN][MAXN], c[MAXN];

void Reset(void) {
    for(int i = 1; i <= N; i++) {
        vec[i].clear();
    }
}

void Init(void) {
    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) f[i][j] = INF;
    }
    for(int i = 1; i <= N; i++) {
        scanf("%d", &c[i]);
    }
    for(int i = 1, x, y; i <= M; i++) {
        scanf("%d%d", &x, &y);
        vec[x].push_back(y);
        vec[y].push_back(x);
    }
}

void Work(void) {
    f[1][N] = 0;
    queue < pair<int, int> > Q;
    Q.push(make_pair(1, N));
    while(Q.size()) {
        int x = Q.front().first, y = Q.front().second;
        Q.pop();
        // if(x == N && y == 1) break;
        for(auto tox : vec[x]) {
            for(auto toy : vec[y]) {
                if(c[tox] == c[toy]) continue;
                if(f[tox][toy] != INF) continue;
                f[tox][toy] = f[x][y] + 1;
                Q.push(make_pair(tox, toy));
                // if(tox == N && toy == 1) break;
            }
        }
        if(f[N][1] != INF) break;
    }
    if(f[N][1] == INF) puts("-1");
    else printf("%d\n", f[N][1]);
}

int main() {
    scanf("%d", &T);
    while(T--) {
        Reset();
        Init();
        Work();
    }
}

F Teleporter Takahashi

#include<bits/stdc++.h>
using namespace std;

int sx, sy, tx, ty, a, b, c, d;

void ot(void) {

}

vector <int> xx, yy;

int main() {
    cin >> sx >> sy >> tx >> ty >> a >> b >> c >> d;
    // if(a == b || c == d) {
    //     ot();
    //     // return 0;
    // }
    int dx = tx - sx, dy = ty - sy;
    int mx = sx + tx, my = sy + ty;
    if(dx % 2 != 0 || dy % 2 != 0) {
        puts("No"); return 0;
    }

    if(a == b && c == d) {
        if(mx / 2 == a && my / 2 == c) {
            puts("Yes");
            printf("%d %d\n", a, c);
        }
        else puts("No");
        return 0;
    }
    //2x - sx, 2y - sy  odd & even not change
    if(dx != 0 && a == b) {
        if((sx + tx) / 2 != a) {
            puts("No"); return 0;
        }
        xx.push_back(a);
        yy.push_back(c);
        sx = 2 * a - sx, sy = 2 * c - sy;
        dx = tx - sx, dy = ty - sy;
    }
    if(dy != 0 && c == d) {
        if((sy + ty) / 2 != c) {
            puts("No"); return 0;
        }
        xx.push_back(a);
        yy.push_back(c);
        sx = 2 * a - sx, sy = 2 * c - sy;
        dx = tx - sx, dy = ty - sy;
    }
    puts("Yes");
    for(int i = 0; i < (int)xx.size(); i++) {
        printf("%d %d\n", xx[i], yy[i]);
    }
    if(dx > 0) {
        while(dx > 0) {
            printf("%d %d\n%d %d\n", a, c, a + 1, c);
            dx -= 2;
        }
    }
    else {
        while(dx < 0) {
            printf("%d %d\n%d %d\n", b, c, b - 1, c);
            dx += 2;
        }
    }
    if(dy > 0) {
        while(dy > 0) {
            printf("%d %d\n%d %d\n", a, c, a, c + 1);
            dy -= 2;
        }
    }
    else {
        while(dy < 0) {
            printf("%d %d\n%d %d\n", a, d, a, d - 1);
            dy += 2;
        }
    }
    return 0;
}

标签:Atcoder,sy,sx,Beginner,int,289,dx,dy,push
From: https://www.cnblogs.com/liubainian/p/17112637.html

相关文章

  • 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=......
  • [ABC266] AtCoder Beginner Contest 266
    比赛链接:Tasks-AtCoderBeginnerContest266先贴代码,题解有空再补。TasksTaskNameTimeLimitMemoryLimitAMiddleLetter2sec1024MBSubmit......
  • Atcoder ABC282F Union of Two Sets
    https://atcoder.jp/contests/abc282/tasks/abc282_fST表板子???这怎么出的?发现要每一个区间都能拆分成至多两个区间,那很明显就能联想到ST表的查询。大概算一下发现......