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

[Luogu] 家族

时间:2018-01-20 14:06:16      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:space   name   problem   get   tar   turn   lan   math   nod   

https://www.luogu.org/problemnew/show/1767

字符串的读入有点麻烦

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;
const int N = 110;

#define yxy getchar()

char A[N][N << 1];
int n, Answer;
int Vis[N][N << 1];
struct Node{int x, y;};
Node Queue[N * N];

inline int read(){
    int x = 0; char c = yxy;
    while(c < 0 || c > 9) c = yxy;
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, c = yxy;
    return x;
}

void Bfs(int x, int y){
    int T = 1, H = 1;
    Node now; now.x = x, now.y = y;
    Queue[H] = now;
    while(H <= T){
        Node topp = Queue[H ++];
        int X = topp.x, Y = topp.y; Node nxt;
        Vis[X][Y] = 1;
        if(!Vis[X][Y + 1]) {nxt.x = X, nxt.y = Y + 1; Queue[++ T] = nxt;}
        if(!Vis[X][Y - 1]) {nxt.x = X, nxt.y = Y - 1; Queue[++ T] = nxt;}
        if(!Vis[X + 1][Y]) {nxt.x = X + 1, nxt.y = Y; Queue[++ T] = nxt;}
        if(!Vis[X - 1][Y]) {nxt.x = X - 1, nxt.y = Y; Queue[++ T] = nxt;}
    }
}

int main()
{
    n = read();
    memset(Vis, -1, sizeof Vis);
    for(int i = 1; i <= n; i ++) gets(A[i] + 1);
    for(int i = 1; i <= n; i ++) {
        int len = strlen(A[i] + 1);
        for(int j = 1; j <= len; j ++){
            Vis[i][j] = 0;
            if(A[i][j] < a || A[i][j] > z) Vis[i][j] = 1;    
        }
    }
    for(int i = 1; i <= n; i ++) {
        int len = strlen(A[i] + 1);
        for(int j = 1; j <= len; j ++){
            if(!Vis[i][j]) Answer ++, Bfs(i, j); 
        }
    }
    printf("%d", Answer);
    return 0;
}

 

[Luogu] 家族

标签:space   name   problem   get   tar   turn   lan   math   nod   

原文地址:https://www.cnblogs.com/shandongs1/p/8320250.html

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