码迷,mamicode.com
首页 > 其他好文 > 详细

周练1

时间:2016-12-11 23:17:18      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:复习   eof   set   empty   max   cstring   ret   lock   cst   

最近一个多月为各种考试复习,感觉整个人学傻了。。今天去集训队练习,虽然训练时长只有两个小时,但感觉好累哦。今晚冒个泡,然后继续滚去复习。。。啊啊啊每周都有考试,呜呜/(ㄒ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\n",b);
            for(int k = 0; k <=len/2; ++k) {
                if(b[k] != b[len-k]) {
                    f = 0;
                    break;
                }
            }
            if(f) {
                printf("%s\n", 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\n1 2\n");
    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\n", l);
    }
    else
        printf("Impossible\n");
    return 0;
}
View Code

 

 

 

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

周练1

标签:复习   eof   set   empty   max   cstring   ret   lock   cst   

原文地址:http://www.cnblogs.com/GraceSkyer/p/6160828.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!