CAPTCHA

Time Limit: 1000 MS Memory Limit: 32768 KB

64-bit integer IO format: %lld , %llu Java class name: Main

Description

A CAPTCHA (Completely Automated Public Turing Test to Tell Computers and Humans Apart) is a program that generates and grades tests that are human solvable, but intends to be beyond the capabilities of current computer programs. This technology is now almost a standard security mechanism for defending against undesirable or malicious Internet bot programs, such as those spreading junk emails and those grabbing thousands of free email accounts instantly.

It is hard for you to make a program to solve it. So, in this moment, you just need to solve a much easier problem.

111111MMM1111111   1MMMMMMMMMMM1111   11111MMMMMMMM111   1MMMMMMMMMMM1111   1MMMMMMMMMMMM111   1MMMMMMMMMMMMM11
11111MM1MM111111 1MM11111111MM111 111MM1111111MM11 1MM111111111MM11 1MM1111111111111 1MM1111111111111
1111MM111MM11111 1MM11111111MM111 11MM111111111MM1 1MM1111111111MM1 1MM1111111111111 1MM1111111111111
111MMMMMMMMM1111 1MMMMMMMMMMM1111 11MM111111111111 1MM1111111111MM1 1MMMMMMMMMMMM111 1MMMMMMMMMMMMM11
11MM1111111MM111 1MM11111111MM111 11MM111111111MM1 1MM1111111111MM1 1MM1111111111111 1MM1111111111111
1MMM11111111MM11 1MM11111111MM111 111MM1111111MM11 1MM111111111MM11 1MM1111111111111 1MM1111111111111
1MM1111111111MM1 1MMMMMMMMMMM1111 11111MMMMMMMM111 1MMMMMMMMMMM1111 1MMMMMMMMMMMM111 1MM1111111111111 11111MMMMMMMM111 1MM111111111MM11 11111MMMMMM11111 1111MMMMMMMM1111 11MM111111MMM111 11MM111111111111
111MM1111111MM11 1MM111111111MM11 1111111MM1111111 1111111MM1111111 11MM11111MMM1111 11MM111111111111
11MM111111111MM1 1MM111111111MM11 1111111MM1111111 1111111MM1111111 11MM111MMM111111 11MM111111111111
11MM111111111111 1MMMMMMMMMMMMM11 1111111MM1111111 1111111MM1111111 11MMMMM111111111 11MM111111111111
11MM111111MMMMM1 1MM111111111MM11 1111111MM1111111 111MM11MM1111111 11MM111MMM111111 11MM111111111111
111MM1111111MM11 1MM111111111MM11 1111111MM1111111 111MMM1MM1111111 11MM11111MMM1111 11MM111111111111
11111MMMMMMMMM11 1MM111111111MM11 11111MMMMMM11111 11111MMMM1111111 11MM111111MMMM11 11MMMMMMMMMMMM11 1MM1111111111MM1 1MMM111111111MM1 11111MMMMMM11111 1MMMMMMMMMMM1111 11111MMMMMM11111 1MMMMMMMMMMM1111
1MMMM111111MMMM1 1MMMM11111111MM1 111MMM1111MMM111 1MM111111111MM11 111MMM1111MMM111 1MM111111111MM11
1MM1MM1111MM1MM1 1MM1MM1111111MM1 11MMM111111MMM11 1MM1111111111MM1 11MMM111111MMM11 1MM1111111111MM1
1MM11MMMMM111MM1 1MM11MM111111MM1 1MM1111111111MM1 1MM111111111MM11 1MM1111111111MM1 1MM111111111MM11
1MM1111M11111MM1 1MM1111MM1111MM1 11MMM111111MMM11 1MMMMMMMMMMM1111 11MMM1MMMM1MMM11 1MMMMMMMMMMM1111
1MM1111111111MM1 1MM111111MMM1MM1 111MMM1111MMM111 1MM1111111111111 111MMM11MMMMM111 1MM11111111MM111
1MM1111111111MM1 1MM11111111MMMM1 11111MMMMMM11111 1MM1111111111111 111111MMMM1MMMM1 1MM111111111MMM1 1111MMMMMMMM1111 11MMMMMMMMMMMM11 1MM1111111111MM1 1MMMM111111MMMM1 1MM1111111111MM1 11MMM111111MMM11
111MM1111111MM11 11MMMMMMMMMMMM11 1MM1111111111MM1 11MMM111111MMM11 1MM1111111111MM1 111MMM1111MMM111
11MMM1111111MMM1 1111111MM1111111 1MM1111111111MM1 11MMM111111MMM11 11MM111MM111MM11 1111MMM11MMM1111
1111MMMMM1111111 1111111MM1111111 1MM1111111111MM1 111MMM1111MMM111 11MM111MM111MM11 111111MMMM111111
1MMM111MMMM11111 1111111MM1111111 1MMM11111111MMM1 1111MMM11MMM1111 11MM111MM111MM11 1111MMM11MMM1111
111MMM11111MMM11 1111111MM1111111 1MMM11111111MMM1 11111MM11MM11111 11MM1MM11MM1MM11 111MMM1111MMM111
11111MMMMMMM1111 1111111MM1111111 111MMMMMMMMMM111 111111MMMM111111 111MMM1111MMM111 11MMM111111MMM11 11MMM111111MMM11 111MMMMMMMMMM111
111MMM1111MMM111 1111111111MM1111
1111MMM11MMM1111 111111111MM11111
111111MMMM111111 11111111MM111111
1111111MM1111111 111111MM11111111
1111111MM1111111 11111MM111111111
1111111MM1111111 111MMMMMMMMMMM11

Assume that the CAPTCHA only consists of upper letters. As you see above, we use a 7 * 16 matrix to represent a letter. The matrix only consists of characters 'M' and '1'. You can make sure that the 'M' elements in each letter matrix are connected. It means the all 'M' elements in each letter matrix belong to only ONE component. One element is connected to its 8 neighboring elements. That is, (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1), (x - 1, y - 1), (x + 1, y - 1), (x - 1, y + 1), (x + 1, y + 1) are (x, y)'s neighbors and they are connected.

And you will be given a bigger matrix, like this:

11111MMMMMM111
1111111MM11111
1MM1111MM11111
1MM1111MM11111
1MM1111MM11111
1MM1111MM11111
1MM11MMMMMM111
1MM11111111111
1MMMMMMMMMMMM1

Your task is to tell which letters appear in this matrix. The answer for this sample is 'I' and 'L'.

What's more, the letter appears in the bigger matrix may rotate 180 degrees, like this:

1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM111MMMMMMMMMMMMM1
1MMM11111111MMM11111111111111MM1
1MMM11111111MMM11111111111111MM1
111MMMMMMMMMM11111MMMMMMMMMMMMM1

'F' and 'U' is the answer for this sample.

OK, it's time for you to finish this work.

Input

There are multiple cases (no more than 10). In the first line, two integers n and m (7 <= n, m <= 300) will be given. Following n lines give the matrix. Each line contains m characters. Each character will be either 'M' or '1'. You may assume that 'M' characters between any pair of letters in the matrix won't be connected, and each 'M' in the matrix belongs to one valid letter.

There is a blank line between cases.

Output

Output the characters appear in the matrix. If a letter appears more than once, just output it ONE time. Sort the answer in alphabet order.

Sample Input

7 32
1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM111MMMMMMMMMMMMM1
1MMM11111111MMM11111111111111MM1
1MMM11111111MMM11111111111111MM1
111MMMMMMMMMM11111MMMMMMMMMMMMM1 15 19
11111MMMMMMMM111111
111MM1111111MM11111
11MM111111111MM1111
11MM111111111111111
11MM111111MMMMM1111
111MM1111111MM11111
11111MMMMMMMMM11111
1111111111111111111
1111MMM111111111MM1
1111MMMM11111111MM1
1111MM1MM1111111MM1
1111MM11MM111111MM1
1111MM1111MM1111MM1
1111MM111111MMM1MM1
1111MM11111111MMMM1

Sample Output

FU
GN
#include <iostream>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#include<stack>
#include<vector>
using namespace std;
int mmap[] = {,,,,,,,,,,,,,,,,,,,,,,,,,};
int used[][];
char ch[][]; int move[][] = {-,-, -,, -,, ,-, ,, ,-, ,, ,};
int n,m;
int dfs(int x,int y)
{
int ans = ;
for(int i=; i<; i++)
{
int tx = x + move[i][];
int ty = y + move[i][];
if(tx < || tx>=n || ty< || ty>=m || used[tx][ty]) continue;
if(ch[tx][ty] == 'M')
{
used[tx][ty] = ;
ans += dfs(tx,ty);
}
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
while(~scanf("%d %d",&n,&m))
{
memset(ch,'\0',sizeof(ch));
for(int i=; i<n; i++)
{
scanf("%s",ch[i]);
}
memset(used,,sizeof(used));
set<char>tt;
int k;
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
if(ch[i][j] == 'M' && used[i][j] == )
{
used[i][j] = ;
int res = dfs(i,j);
if(res == ) tt.insert('I');
else if(res == ) tt.insert('L');
else if(res == ) tt.insert('J');
else if(res == ) tt.insert('Y');
else if(res == ) tt.insert('Z');
else if(res == ) tt.insert('A');
else if(res == ) tt.insert('H');
else if(res == ) tt.insert('E');
else if(res == ) tt.insert('Q');
else if(res == ) tt.insert('B');
else if(res == ) /// C T;
{
int tmp = ;
for(k = j; ch[i][k] == 'M'; k++)
{
tmp++;
}
if(tmp == ) tt.insert('C');
else tt.insert('T');
}
else if(res == ) ///F K
{
int tmp = ;
for(k = j; ch[i][k] == 'M'; k++)
{
tmp++;
}
if(tmp == ) tt.insert('K');
else if(tmp > ) tt.insert('F');
else if(ch[i+][j+] == 'M') tt.insert('K');
else tt.insert('F');
}
else if(res == ) /// G P U
{
int tmp = ;
for(k = j; ch[i][k] == 'M'; k++)
{
tmp++;
}
if(tmp == || tmp == ) tt.insert('G');
else if(tmp == ) tt.insert('P');
else if(tmp == ) tt.insert('U');
else if(ch[i+][j] == 'M') tt.insert('P');
else tt.insert('U');
}
else if(res == ) ///O V W X
{
int tmp = ;
for(k = j; ch[i][k] == 'M'; k++)
{
tmp++;
}
if(tmp == ) tt.insert('O');
else if(tmp == ||tmp == ) tt.insert('V');
else if(tmp == ) tt.insert('W');
else if(ch[i+][j] == 'M') tt.insert('W');
else tt.insert('X');
}
else if(res == ) /// D M N
{
int tmp = ;
for(k = j; ch[i][k] == 'M'; k++)
{
tmp++;
}
if(tmp == ) tt.insert('M');
else if(tmp == )tt.insert('D');
else tt.insert('N');
}
else if(res == ) ///R S
{
int tmp = ;
for(k = j; ch[i][k] == 'M'; k++)
{
tmp++;
}
if(tmp == || tmp == ) tt.insert('S');
else tt.insert('R');
}
}
}
}
for(set<char>::iterator it = tt.begin(); it != tt.end(); ++it)
{
putchar(*it);
}
cout<<endl;
}
return ;
}

ZOJ-3314的更多相关文章

  1. zoj 3314 CAPTCHA(纯模拟)

    题目 有些人用深搜写的,当然我这弱弱的,只理解纯模拟... 纯模拟,第一次写了那么长的代码,我自己也是够坚韧不拔的,,,,必须留念啊!!! 注意,G包含C,E包含L,R包含P,(照图说O应该不包含C, ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  4. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  5. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  8. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  9. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

  10. ZOJ 1958. Friends

    题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...

随机推荐

  1. 关于Javac编译器的那点事(一)

    Javac是什么? 它是一种编译器,将Java对人非常友好的语言,编译转化对所有机器都非常友好的语言,即:JVM能够识别的语言,也就是Java字节码.而Java字节码,说白了就是一连串二进制数字. J ...

  2. HDU 5249 离线树状数组求第k大+离散化

    KPI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. Codeforces Round #311 (Div. 2)B. Pasha and Tea二分

    B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. JQuery学习二(获取元素控件并控制)

    $(’#id‘).+function; 例如: 1 <head> 2 <title>JQuery</title> 3 <script src="js ...

  5. Qt -------- 多线程编程

    一.继承QThread(不推荐) 定义一个类,继承QThread,重写run(),当调用方法start(),启动一个线程,run()函数运行结束,线程结束. 二.继承QRunnable Qrunnab ...

  6. How to configue session timeout in Hive

    This article explains how to configure the following settings in Hive:hive.server2.session.check.int ...

  7. ELK6.0环境搭建及配置

    ELK环境搭建及配置 ElasticSearch在5.x后的安装和插件的官方执行更好了,head插件官方默认集成在kibana的dev tools里,支持rpm包方式安装,x-pack安装后支持权限及 ...

  8. Django1.5 自定义用户模型(总结)

    Django系统有自带的超级棒的认证机制,但是默认的用户模型有一点捉急,为了自定义用户模型,看了很多相关的文章,这里做一个总结: 你可以先看一下这篇,对Django的用户模型有一个比较全的了解: 来自 ...

  9. UVA 1645 Count

    https://vjudge.net/problem/UVA-1645 题意:有多少个n个节点的有根树,每个深度中所有节点的子节点数相同 dp[i] 节点数为i时的答案 除去根节点还有i-1个点,如果 ...

  10. 【C++对象模型】第二章 构造函数语意学

    1.Default Constructor 当编译器需要的时候,default constructor会被合成出来,只执行编译器所需要的任务(将members适当初始化). 1.1  带有 Defau ...