Codeforces Round #290 (Div. 2) b

/**
 * @brief Codeforces Round #290 (Div. 2) b
 * @file a.cpp
 * @author mianma
 * @created 2015/02/04 15:17
 * @edited  2015/02/04 15:17
 * @type brute
 * @note
 */
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

#define max(a, b)  ((a) > (b) ? (a) : (b))
#define min(a, b)  ((a) > (b) ? (b) : (a))
#define abs(a)     ((a) >  0  ? (a) : (0 - (a)))
#define CLR(vec)   memset(vec, 0, sizeof(vec))

#ifdef DEBUG
ifstream in;
ofstream out;
#define CIN in
#define COUT out
#else
#define CIN cin
#define COUT cout
#endif

#define MAXN 55
#define MAXD 4

char g[MAXN][MAXN];
int vis[MAXN][MAXN];

struct s_dir{
    int x;
    int y;
}dir[MAXD] = {
    {-1, 0},
    {1, 0},
    {0, 1},
    {0, -1},
};

int m, n;
int xb, yb;

static inline bool brute(int x, int y, char color, int cnt){
    if(x <= 0 || x > m || y <= 0|| y > n || g[x][y] != color) return false;
#ifdef  DEBUG
    //COUT << x << " " << y << "->" << cnt << "|||" << m << " " << n << " " << color << "
" ;
#endif
    if(vis[x][y]){
        if(xb == x && yb == y && cnt >= 4)
            return true;
        else
            return false;
    }
    vis[x][y] = true;
    for(int i = 0; i < MAXD; i++){
            if(brute(x + dir[i].x, y + dir[i].y, color, cnt + 1))
                    return true;
    }
    return false;
}

int main(void){
    ios_base::sync_with_stdio(0);
#ifdef DEBUG
    CIN.open("./in",  ios::in);
    COUT.open("./out",  ios::out);
#endif
    CIN >> m >> n;
    int cnt;
    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= n; j++){
                CIN >> g[i][j];
        }

    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= n; j++){
            CLR(vis);
            xb = i, yb = j;
            cnt = 1;
            if(brute(i, j, g[i][j], cnt)){
                COUT << "Yes
";
                return 0;
            }
        }
    COUT << "No
";
    return 0;
}
时间: 02-02

Codeforces Round #290 (Div. 2) b的相关文章

Codeforces Round #290 (Div. 2) B (dfs)

题目链接:http://codeforces.com/problemset/problem/510/B 题意:判断图中是否有某个字母成环 思路:直接dfs就好了,注意判断条件:若下一个字母与当前字母相同且已搜过,则存在满足题意的环 代码: 1 #include <bits/stdc++.h> 2 #define MAXN 60 3 using namespace std; 4 5 int mp[MAXN][MAXN], vis[MAXN][MAXN], m, n; 6 int dir[4][2

Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)

http://codeforces.com/problemset/problem/510/B #include "cstdio" #include "cstring" int r,c; char map[55][55]; int vis[55][55]; int mark; int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1}; int judge(int x,int y) { if(x<0||x>=r||y<0||y>

Codeforces Round #290 (Div. 2) C. Fox And Names 拓扑排序

C. Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: t

Codeforces Round #290 (Div. 2)

A题: 简单的模拟. 贴样例就知道了. input 3 3 output ###..#### input 3 4 output ####...##### input 5 3 output ###..#####..### input 9 9 output #########........###########........#########........###########........######### 1 #include<cstdio> 2 int main() 3 { 4 in

Codeforces Round #290 (Div. 2) 解题报告 A.B.C.D.

A - Fox And Snake 模拟. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h> using na

Codeforces Round #290 (Div. 2) 拓扑排序

C. Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: t

B. Fox And Two Dots Codeforces Round #290 (Div. 2)

B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n?×?m ce

C. Fox And Names Codeforces Round #290 (Div. 2)

C. Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: t

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/