• 周练1


    最近一个多月为各种考试复习,感觉整个人学傻了。。今天去集训队练习,虽然训练时长只有两个小时,但感觉好累哦。今晚冒个泡,然后继续滚去复习。。。啊啊啊每周都有考试,呜呜/(ㄒoㄒ)/~~

    CodeForces 586D Phillip and Trains(bfs)

    第一遍提交时忘记对选入队列的状态进行标记导致MLE(我真的傻了。。)

    其实这题还挺裸的。。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<string>
    #include<cmath>
    #define CLR(a,b) memset((a),(b),sizeof((a)))
    using namespace std;
    
    const int inf = 0x3f3f3f3f;
    const int N = 1001;
    int n, k;
    char s[4][105];
    int mp[4][105];
    int vis[4][105];
    int f;
    
    struct qnode {
        int x, y;
        qnode(int x = 0, int y = 0):x(x),y(y) {}
    };
    
    void bfs(int x) {
        queue<qnode>q;
        q.push(qnode(x, 0));
        while(!q.empty()) {
            int x = q.front().x;
            int y = q.front().y;
            q.pop();
    
            y++;
    
            if(mp[x][y]) continue;
    
            if(y >= n-1) {f = 1; return;}
    
            for(int i = -1; i <= 1; ++i) {
                int xx = x + i;
                if(xx < 0 || xx > 2) continue;
                if(mp[xx][y] || mp[xx][y+1] || mp[xx][y+2] || vis[xx][y+2])
                    continue;
                if(y+2 >= n-1) {f = 1; return;}
                vis[xx][y+2] = 1;
                q.push(qnode(xx, y+2));
            }
        }
    }
    int main() {
        int t, i, j;
        scanf("%d", &t);
        while(t--) {
            f = 0;
            CLR(mp, 0);
            CLR(vis, 0);
    
            scanf("%d%d", &n, &k);
            for(i = 0; i < 3; ++i) {
                scanf("%s", s[i]);
                for(j = 0; j < n ; ++j) {
                    if(s[i][j] >= 'A' && s[i][j] <= 'Z') {
                        mp[i][j] = 1;   //列车
                    }
                }
            }
            for(i = 0; i < 3; ++i) if(s[i][0] == 's') { bfs(i); break;}
            if(f) puts("YES");
            else puts("NO");
        }
        return 0;
    }
    View Code

    CodeForces 505A  Mr. Kitayuta's Gift

    数据小,毫不犹豫暴力解水题。

    #include<cstdio>
    #include<cstring>
    using namespace std;
    char a[12];
    char b[12];
    int main() {
        scanf("%s", a);
        int j;
        int f = 1;
        int ff = 0;
        int len = strlen(a);
        for(int i = 0; i <= len; ++i) {
            for(char c = 'a'; c <= 'z'; c ++) {
                j = 0;
                while(j < i){
                     b[j] = a[j];
                     j++;
                }
                b[j++] = c;
                while(j <= len) {
                      b[j] = a[j-1];
                      j++;
                }
                //printf("%s
    ",b);
                for(int k = 0; k <=len/2; ++k) {
                    if(b[k] != b[len-k]) {
                        f = 0;
                        break;
                    }
                }
                if(f) {
                    printf("%s
    ", b);
                    ff = 1;
                    break;
                }
                if(!f) f = 1;
            }
            if(ff) break;
        }
        if(!ff)
            puts("NA");
        return 0;
    }
    View Code

    CodeForces 493D  Vasya and Chess

    今天最简单的题了~对称博弈~

    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main() {
        int n;
        scanf("%d", &n);
        if(n&1) {
            puts("black");
        }
        else
            printf("white
    1 2
    ");
        return 0;
    }
    View Code

    CodeForces 416A  Guess a number!

    还是签到题。我还是这么水。。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    char a[3];
    char b[3];
    const int inf = 0x3f3f3f3f;
    int main() {
        int n;
        int x;
        int l = -inf, r = inf;
        scanf("%d", &n);
        for(int i = 0; i < n; ++i) {
            scanf("%s %d %s", a, &x, b);
            if(strcmp(a, "<=") == 0 && strcmp(b, "Y") == 0 ||
               strcmp(a, ">") == 0 && strcmp(b, "N") == 0) { // <=
                r = min(x, r);
            }
            else if(strcmp(a, "<") == 0 && strcmp(b, "Y") == 0 ||
               strcmp(a, ">=") == 0 && strcmp(b, "N") == 0) { // <
               r = min(x-1, r);
            }
            else if(strcmp(a, ">=") == 0 && strcmp(b, "Y") == 0 ||
               strcmp(a, "<") == 0 && strcmp(b, "N") == 0) { // >=
               l = max(x, l);
            }
            else { // >
                l = max(x+1, l);
            }
        }
        if(l <= r) {
            printf("%d
    ", l);
        }
        else
            printf("Impossible
    ");
        return 0;
    }
    View Code

    头疼,还有两题没时间看了,堆到下个月期末考试结束后再补。。。

  • 相关阅读:
    NPIV介绍
    PowerShell随笔2_分支 选择 循环 特殊变量
    socket编程原理
    Linux查看物理CPU个数、核数、逻辑CPU个数
    Markdown 使用指南
    Linux Socket
    YoutubeAPI使用
    Youtube API数据类型
    Linux wpa_cli 调试方法
    linux网络编程
  • 原文地址:https://www.cnblogs.com/GraceSkyer/p/6160828.html
Copyright © 2020-2023  润新知