Zoj1628--Diamond(Dfs《暴力》)

Diamond


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Diamond mine is a mini-game which is played on an 8 * 8 board as you can see below.

The board is filled with different colors of diamonds. The player can make one move at a time. A move is legal if it swaps two adjacent diamonds(not diagonally) and after that, there are three or more adjacent diamonds in a row or column with the same color. Those diamonds will be taken away and new diamonds will be put in their positions. The game continues until no legal moves exist.

Given the board description. You are going to determine whether a move is
legal.

Input

The input contains several cases. Each case has exactly 9 lines. The first 8
lines each contains a string of 8 characters. The characters are ‘R‘(Red),
‘O‘(Orange), ‘G‘(Green), ‘P‘(Purple), ‘W‘(White), ‘Y‘(Yellow) or ‘B‘(Blue). All
characters are uppercase. No 3 diamonds of the same color are initially in
adjacent positions in a row or column. The last line has 4 integers in the form
" row1 column1 row2 column2" describing the postions of the 2 diamonds that the
player wants to swap. Rows are marked 1 to 8 increasingly from top to bottom
while columns from left to right. Input is terminated by EOF.

Output

For each case, output "Ok!" if the move is legal or "Illegal move!" if it is
not.

Sample Input

PBPOWBGW
RRPRYWWP
YGBYYGPP
OWYGGRWB
GBBGBGGR
GBWPPORG
PPGORWOG
WYWGYWBY
4
3 3
3
PBPOWBGW
RRPRYWWP
YGBYYGPP
OWYGGRWB
GBBGBGGR
GBWPPORG
PPGORWOG
WYWGYWBY
5
5 6 5


Sample Output

Ok!
Illegal move!



Author: PAN, Minghao
Source: ZOJ Monthly, June
2003

话说一不小心WA了一晚上, 我nm。

ac码:

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
char map[10][10];
bool Dfs(int a, int b)    //相当于往四个方向搜。
{
    int flag1 = 0, flag2 = 0;
    for(int i = a; i >= 1; i--)
    {
        if(map[i][b] == map[a][b])
            flag1++;
        else
            break;
    }
    for(int i = a+1; i <= 8; i++)
    {
        if(map[i][b] == map[a][b])
            flag1++;
        else
            break;
    }
    if(flag1 >= 3)
        return true;
    for(int i = b; i >= 1; i--)
    {
        if(map[a][i]==map[a][b])
            flag2++;
        else
             break;
    }
    for(int i = b + 1; i <= 8; i++)
    {
        if(map[a][i]== map[a][b])
            flag2++;
        else
            break;
    }
    if(flag2 >= 3)
        return true;
    return false;
}
int main()
{
    while(cin >> map[1][1])
    {
        for(int i = 1; i <= 8; i++)
            for(int j = 1; j <= 8; j++)
            {
                if(i == 1 && j == 1)
                    continue;
                else
                    cin >> map[i][j];
            }
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        if(abs(a-c) + abs(b-d) != 1){                           //xiaojianzhi
            printf("Illegal move!\n");
            continue;
        }
        char s;
        s = map[a][b];map[a][b] = map[c][d]; map[c][d] = s;   //  swap position.
        if(Dfs(a, b) || Dfs(c, d))
            printf("Ok!\n");
        else
            printf("Illegal move!\n");
    }
    return 0;
} 
时间: 2025-01-31 06:51:58

Zoj1628--Diamond(Dfs《暴力》)的相关文章

hdu 5024 Wang Xifeng&#39;s Little Plot (dfs+暴力)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 131 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

Codeforces 6D Lizards and Basements 2 dfs+暴力

题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a

ACM: Gym 100935G Board Game - DFS暴力搜索

Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 100935G Description standard input/outputStatements Feras bought to his nephew Saleem a new game to help him learning calculating. The game consists of a boar

NOIP 2002提高组 选数 dfs/暴力

1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合与它们的和为: 3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34. 现在,要求你计算出和为素

ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Practice Description Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle

hdu1015 dfs暴力搜索所有情况模板

脑子有点坑,不知道为什么,可能以前遇到阴影了,现在看到dfs暴力搜有种莫名的害怕,总结一下模板吧 这题还是没意思的,直接暴力搜,不过我写的很烂,可能就是这个原因吧,看了别人的模板,觉得不错. 学了个单词”lexicography“ 字典序,又吃了没文化的亏,wa一次 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath>

Codeforces Round #286 (Div. 2)B. Mr. Kitayuta&#39;s Colorful Graph(dfs,暴力)

数据规模小,所以就暴力枚举每一种颜色的边就行了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm>

hdu 1010 Tempter of the Bone(dfs暴力)

Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried despe

hdu4277USACO ORZ dfs暴力枚举+map

//给N个 问rails用着N个rails能构成几个不同的三角形 //dfs暴力枚举+(map) #include<cstdio> #include<cstring> #include<map> #include<iostream> using namespace std ; int ans ; int a[20] ; int n ; int sum = 0 ; struct node { int a , b , c ; bool operator == (

很好的脑洞题:dfs+暴力 Gym - 101128A Promotions

http://codeforces.com/gym/101128 题目大意:给你一个a,b,e,p.有e个点,p条有向边,每条边为(x,y),表示x->y,每次我们都取出一个入度为0的,并且一次性取出来的个数为a(或b).当然,取出来的种类可能有很多种(即一个集合),问,这个集合中有多少个数字是相同的. 第一个输出集合长度为a的,第二个输出集合长度为b的,第三个输出无论如何都无法被取出的个数. 思路:建立正向图和反向图. 定义pair<int, int> interval[i] 表示第i