codechef September Challenge 2018 Division 2 A-F

比赛链接

上紫啦hhh,好开心

每个题里面都有中文翻译,我就不说题意了。。

A

直接模拟即可

#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
const int MAXN = 1e5 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();}
    while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar();
    return x * f;
}
int T;
int a[MAXN], pos, Q, N;
main() {
    T = read();
    while(T--) {
        N = read(); pos = read(); Q = read();
        for(int i = 1; i <= N; i++) a[i] = i;
        while(Q--) {
            int x = read(), y = read();
            swap(a[x], a[y]);
        }
        for(int i = 1; i <= N; i++)
            if(pos == a[i]) {
                printf("%d\n", i); break;
            }
    }
}

A

B

这题我交了五遍没过,捂脸,然而并不知道自己哪里错了

跟lyq说了说还被婊了一顿。。。。最后换了个写法A了。。

直接大力特判就行,至于哪个share什么玩意儿就让N-1,M-1,然后判是否可行

#include<cstdio>
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();}
    while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar();
    return x * f;
}
int N, M, X, Y;
int pd(int N, int M) {
    /*if(N == 0 && M == 0) return 1;
    else if((N < X) || (M < Y)) return 0;
    else if(N % X == 0 && M % Y == 0) return 1;
    else return 0;*/
    if(N < 0 || M < 0) return 0;
    return N % X == 0 && M % Y == 0;
}
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        N = read(), M = read(), X = read(), Y = read();
        N--; M--;
        if(pd(N, M)) {puts("Chefirnemo"); continue;}
        N--; M--;
        if(pd(N, M)) {puts("Chefirnemo"); continue;}
        puts("Pofik");
    }
    return 0;
}

B

C

这题就有点厉害了!

结论:哥德巴赫猜想在信息学奥赛的范围内是成立的!

也就是说,任意一个$>=4$的偶数都是合法的。

然后把奇数和$0$判掉,维护出$0, 1$的个数即可

#include<cstdio>
#define LL long long
using namespace std;
const int MAXN = 1e6 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();}
    while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar();
    return x * f;
}
int T;
int N;
int a[MAXN];
LL tim[MAXN];
LL calc(LL x) {
    return x * (x - 1) / 2;
}
int main() {
  //  printf("%d", 2 ^ 4);
    T = read();
    while(T--) {
        N = read();
        for(int i = 1; i <= N;i ++) a[i] = read(), tim[a[i]]++;
        LL ans = 0, ze = 0, on = 0;
        /*for(int i = 1; i <= N; i++) {
            for(int j = i + 1; j <= N; j++) {
                int x = (a[i] ^ a[j]);
                if((!(x & 1)) && (x != 2) && (x != 0)) ans++;
            }
        }*/

        for(int i = 1; i <= N; i++)
            if(a[i] & 1) on++;
            else ze++;
        ans = calc(ze) + calc(on);
        //printf("%d\n", ans);
        LL a1 = 0;
        for(int i = 1; i <= N; i++)
            a1 += tim[a[i] ^ 2];
        ans -= a1 / 2;
        for(int i = 1; i <= N; i++) {
            ans -= (tim[a[i]] * (tim[a[i]] - 1)) / 2, tim[a[i]] = 0;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

C

D

爆搜打出前$8$的表,不难找到规律:

最小的一定是$n, 1, 2, 3, \dots n - 1$

最大的是:$2, 3, 4, 5, n / 2, 1, 2 + n / 2, 3 + n / 2, 4 + n  /2 ...$

奇数的话还要特殊考虑一下倒数第二位

#include<cstdio>
#include<map>
#include<iostream>
#define ull unsigned long long
#define LL long long
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 7;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();}
    while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar();
    return x * f;
}
int N;
int ans[MAXN], num;
int main() {
//    freopen("a.out", "w", stdout);
    N = read();

    for(int i = 2; i <= N / 2; i++) ans[++num] = i;
    ans[++num] = 1;
    for(int i = 2; i <= N / 2; i++) ans[++num] = N / 2 + i;
    ans[++num] = 1 + N / 2;
    for(int i = 1; i <= num - 1; i++)
        printf("%d ", ans[i]);
    if(N & 1) printf("%d ", N);
    printf("%d\n", ans[num]);
    printf("%d ", N);
    for(int i = 1; i <= N - 1; i++)
        printf("%d ",i);
    return 0;
}

D

E

首先考虑暴力怎么打,我们把给出的初始行列的01取反,这样$0$的时候对应的是必胜态,$1$对应的是必败态。

然后按博弈论的定义推,$(i, j)$若是必胜态,那么至少有$(i - 1, j)$是必败态 或者 $(i, j - 1)$是必败态。

然后暴力枚举一遍就行了,复杂度$O(NM)$

接下来的操作就比较神仙了,,打表 或 直接观察式子可得,若第$(i, j)$个点是必败点,那么它所在的对角线往后的点,都是必败点!

这样我们就把状态降到了$2 * M$

那最开始的必败点怎么求呢?

直觉告诉我们 稍加证明不难得到,这种点一定是出现在前两行 或者前两列。

然后就做完了。

暴力推前两行 前两列即可。

保险起见我推了三行三列。

#include<cstdio>
#include<cstring>
#include<vector>
#define LL long long
using namespace std;
const int MAXN = 1e5 + 10;
inline LL read() {
    char c = getchar(); LL x = 0, f = 1;
    while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();}
    while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar();
    return x * f;
}
int T;
int a[4][MAXN], b[MAXN][4], N, M, f[MAXN], g[MAXN];
char A[MAXN], B[MAXN];
int main() {
//-    freopen("a.out", "w", stdout);
    int T = read();
    while(T--) {
        scanf("%s", A + 1);
        scanf("%s", B + 1);
        M = strlen(A + 1);
        N = strlen(B + 1);
        for(int i = 1; i <= M; i++) a[0][i] = (A[i] == ‘1‘ ? 0 : 1);
        for(int i = 1; i <= 3; i++) a[i][0] = (B[i] == ‘1‘ ? 0 : 1);

        for(int i = 1; i <= 3; i++) b[0][i] = (A[i] == ‘1‘ ? 0 : 1);
        for(int i = 1; i <= N; i++) b[i][0] = (B[i] == ‘1‘ ? 0 : 1);

        memset(f, 0x7f, sizeof(f));
        memset(g, 0x7f, sizeof(g));

        for(int i = 1; i <= 3; i++) {
            for(int j = 1; j <= M; j++) {
                if(a[i - 1][j] == 1 || a[i][j - 1] == 1) a[i][j] = 0;//能到达必败节点的
                else a[i][j] = 1;
                if(a[i][j] == 1) f[j - i + 1] = min(f[j - i + 1], i);
            }
        }

        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= 3; j++) {
                if(b[i - 1][j] == 1 || b[i][j - 1] == 1) b[i][j] = 0;
                else b[i][j] = 1;
                if(b[i][j] == 1) g[i - j + 1] = min(g[i - j + 1], j);
            }
        }
        vector<int> ans;
        int Q = read();
        while(Q--) {
            int x = read(), y = read();
            int dy = y - x + 1,
                dx = x - y + 1;
            if(dy >= 1) {
                if(x >= f[dy]) ans.push_back(0);
                else ans.push_back(1);
            } else {
                if(y >= g[dx]) ans.push_back(0);
                else ans.push_back(1);
            }
        }
        for(int i = 0; i < ans.size(); i++) printf("%d", ans[i]);
        puts("");
    }

    return 0;
}

E

F

这个题我就不说啥了,challenge题嘛,xjb乱搞。

但是!!!

我TM辛辛苦苦写了半天的贪心324分??

直接输出$1$有400+????????????

原文地址:https://www.cnblogs.com/zwfymqz/p/9664759.html

时间: 2024-10-09 22:36:28

codechef September Challenge 2018 Division 2 A-F的相关文章

Codechef October Challenge 2018 游记

Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小厨用了另外一种规则:双方每累计得 K 分才会交换发球权.比赛开始时,由大厨发球. 给定大厨和小厨的当前得分(分别记为 P1 和 P2),请求出接下来由谁发球. 思路: \((P1+P2)\%K\)判断奇偶性即可. 代码链接 BITOBYT - Byte to Bit 题目大意: 在字节国里有三类居民

June Challenge 2018 Division 2

Naive Chef 暴力 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main() { 5 int T; 6 scanf("%d", &T); 7 while(T--){ 8 int N, A, B, x, ca = 0, cb = 0; 9 scanf("%d %d %d", &N, &A, &B); 10 for(int i = 1; i <

codechef September Challenge 2017 Fill The Matrix

这道题我们发现0就代表相同1代表少1或者大1 那么我们根据题目连边 如果存在1(边权只为或0)个数为奇数的环就是无解 #include<cstdio> #include<cstring> #include<algorithm> const int M=1e6+7; int read(){ int ans=0,f=1,c=getchar(); while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();} while(c&

CodeChef February Challenge 2018 Broken Clock (三角函数推导 + 矩阵快速幂)

题目链接  Broken Clock   中文题面链接 令$cos(xα) = f(x)$ 根据三角函数变换公式有 $f(x) = \frac{2d}{l} f(x-1) - f(x-2)$ 令$f(x) = \frac{g(x)}{l^{x}}$ $\frac{g(x)}{l^{x}} = \frac{2d}{l} * \frac{g(x-1)}{l^{x-1}} - \frac{g(x-2)}{l^{x-2}}$ $g(x) = 2dg(x-1) - l^{2}g(x-2)$ 原文地址:ht

Codechef July Challenge 2014部分题解

Dish Owner(并查集) 链接:http://www.codechef.com/JULY14/problems/DISHOWN/ 题意分析:本题主要操作就是给出0 x y时,拥有第x道菜的厨师与拥有第y道菜的厨师pk,谁拥有的所有菜的其中一道菜(不一定是x或y)的分值比较高谁就获胜,并赢得loser的所有菜.即比较的是每个人分值最高的菜,所以对于非loser的人来说,他的分值最高的菜是不变的.综合题意用并查集易解. #include <cstdio> const int Maxn=100

Codeforces Avito Code Challenge 2018 D. Bookshelves

Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/D Description Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive

Codechef March Challenge 2014——The Street

The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. The String street is known as the busiest street in Cod

CodeChef April Challenge 2019题解

传送门 \(Maximum\ Remaining\) 对于两个数\(a,b\),如果\(a=b\)没贡献,所以不妨假设\(a<b\),有\(a\%b=a\),而\(b\%a<a\).综上,我们可以发现答案就是严格次大值 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(R i

CodeChef November Challenge 2014

重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: 1 #include <cstdio> 2 #include <iostream> 3 #include <map> 4 #include <cstring> 5 #include <cstdlib> 6 #include <cmath> 7 #include <algorithm> 8 #