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. BZOJ1068:[SCOI2007]压缩——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1068 Description 给一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中的重复 ...

  2. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  3. c#中文件流的读写

    文件流读入:第一static void Main(string[] args) { //C#文件流写文件,默认追加FileMode.Append string msg = "okffffff ...

  4. bzoj2330: [SCOI2011]糖果(差分约束)

    差分约束裸题,a==b的话分别建a>=b a<=b的边就行.倒序加边不然会TLE是什么鬼 #include<iostream> #include<cstring> ...

  5. poco普通线程

    #include "Poco/Thread.h" #include "Poco/RunnableAdapter.h" #include <iostream ...

  6. maven根据不同的运行环境,打包不同的配置文件(转载)

    使用maven管理项目中的依赖,非常的方便.同时利用maven内置的各种插件,在命令行模式下完成打包.部署等操作,可方便后期的持续集成使用. 但是每一个maven工程(比如web项目),开发人员在开发 ...

  7. UVA10462:Is There A Second Way Left? (判断次小生成树)

    Is There A Second Way Left? Description: Nasa, being the most talented programmer of his time, can’t ...

  8. bzoj 3246 [Ioi2013]Dreaming 贪心

    [Ioi2013]Dreaming Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 638  Solved: 241[Submit][Status][Di ...

  9. js_!和!!的使用

    js中有些特殊的数据(“” 0 null undefined NaN),请求后台返回的数据中往往都有一些这样的数据,需要对这些数据进行过滤. 过滤代码 var a = 0;//0 "&quo ...

  10. 顺序图(Sequence Diagram)

    顺序图(Sequence Diagram): 是一种强调对象间消息传递次序的交互图,又称为时序图或序列图.描述了在一个用例或操作的执行过程中对象如何通过消息相互交互,说明了消息如何在对象之间被发送和接 ...