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. 20165218 2017-2018-1 《Java程序设计》第一周学习总结

    20165218 2017-2018-1 <Java程序设计>第一周学习总结 教材学习内容总结 第一章.Java入门 1. Java特点 Java具有简单.面向对象.平台无关.多线程.动态 ...

  2. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  3. mysql语句及执行计划

    数据库链接: mysql -uroot -p <!--数据库连接-->mysql -h10.0.0.100 -uuser -passwordshow databases <!--查看 ...

  4. wildcard ,notdir ,patsubst ,obj=$(dir:%.c=%.o)

    Makefile中wildcard的介绍 在Makefile规则中,通配符会被自动展开.但在变量的定义和函数引用时,通配符将失效.这种情况下如果需要通配符有效,就需要使用函数“wildcard”,它的 ...

  5. select2 全拼以及首字母

    转自:https://blog.csdn.net/kanhuadeng/article/details/78475317 具体实现方法为: 首先需要在网上下载select2的源码,并引入到项目中,具体 ...

  6. Codeforces Round #398 (Div. 2) B,C

    B. The Queue time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. 使用html5的Geolocation API实现定位

    公司有个需求,需要获取用户的位置,所以看了下html5的Geolocation 这个新东西,发现挺好用的. <!DOCTYPE html> <html> <body> ...

  8. Android应用自动更新功能的代码实现(转)

    由于Android项目开源所致,市面上出现了N多安卓软件市场.为了让我们开发的软件有更多的用户使用,我们需要向N多市场发布,软件升级后,我们也必须到安卓市场上进行更新,给我们增加了工作量.因此我们有必 ...

  9. 2015/9/20 Python基础(16):类和实例

    面向对象编程编程的发展已经从简单控制流中按步的指令序列进入到更有组织的方式中,依靠代码块可以形成命名子程序和完成既定的功能.结构化的或过程性编程可以让我们把程序组织成逻辑快,以便重复或重用.创造程序的 ...

  10. 结合promise对原生fetch的两个then用法理解

    前言:该问题是由于看到fetch的then方法的使用,产生的疑问,在深入了解并记录对promise的个人理解 首先看一下fetch请求使用案例: 案例效果:点击页面按钮,请求当前目录下的arr.txt ...