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. ZOJ1937:Addition Chains——题解

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1937 题目大意:创造一个数列,使得它: 1.单调不递减. 2.其中一个元素 ...

  2. Hydra—密码爆破神器

    公司邮箱系统密码复杂度规则:字母大小写.数字.特殊字符,四选三,长度8位以上.这种复杂度的密码看着是比较安全的,但因历史原因,邮箱系统开放了外网登陆权限,加之公司人数众多,必然会有少量员工把自己的密码 ...

  3. c#中文件流的读写

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

  4. HDU3068:最长回文(Manacher模板)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. PowerDesigner逆向生成

    人越长大话越少,我们不再说今天受了委屈,不再说谁谁谁不理我了我好难过,不再分享生活中的琐事. 我知道人和人之间没法互相理解,大家都很忙,针也没扎在别人身上. 所以把那些还没说出口的话消化在每一步走过的 ...

  6. 牛客多校第五场-D-inv

    链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...

  7. [洛谷P2375] [NOI2014]动物园

    洛谷题目链接:[NOI2014]动物园 题目描述 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决 ...

  8. 【C++ STL】容器的选择

    c++提供了各具特长的容器,那么我们该如何选择最佳的容器? 缺省状态下应该选择vector,因为vector内部结构最简单,并允许随机存取,所以数据的存取十分方便,数据的处理也快. 如果经常要在头部和 ...

  9. RDLC - 后台代码直接导出Excel/PDF/Word格式

    最近做报表功能,用到了.net的报表组件rdlc. 其中有个功能就是后台代码直接输出Excel/PDF/Word格式的文件,网上看了些资源,做个总结: 参考地址 我直接贴出代码: //自动导出exce ...

  10. 【Foreign】K优解 [堆]

    K优解 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定n个行数,每行m个.在每行中选出一个数来,求出前 k 小的异或和. Input 第 ...