hdu 4119 Isabella's Message

时间:2021-12-09 23:24:24

Isabella's Message

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1365 Accepted Submission(s): 400

Problem Description
Isabella and Steve are very good friends, and they often write letters to each other. They exchange funny experiences, talk about people around, share their feelings and write about almost everything through the letters. When the letters are delivered, they are quite afraid that some other people(maybe their parents) would peek. So they encrypted the letter, and only they know how to decrypt it. This guarantees their privacy.

The encrypted message is an N * N matrix, and each grid contains a character.

Steve uses a special mask to work as a key. The mask is N * N(where N is an even number) matrix with N*N/4 holes of size 1 * 1 on it.

The decrypt process consist of the following steps:

1. Put the mask on the encrypted message matrix

2. Write down the characters you can see through the holes, from top to down, then from left to right.

3. Rotate the mask by 90 degrees clockwise.

4. Go to step 2, unless you have wrote down all the N*N characters in the message matrix.

5. Erase all the redundant white spaces in the message.

For example, you got a message shown in figure 1, and you have a mask looks like figure 2. The decryption process is shown in figure 3, and finally you may get a message "good morning".

hdu 4119 Isabella's Message

You can assume that the mask is always carefully chosen that each character in the encrypted message will appear exactly once during decryption.

However, in the first step of decryption, there are several ways to put the mask on the message matrix, because the mask can be rotated (but not flipped). So you may get different results such as "od morning go" (as showed in figure 4), and you may also get other messages like "orning good m", "ng good morni".

hdu 4119 Isabella's Message

Steve didn't know which direction of the mask should be chosen at the beginning, but after he tried all possibilities, he found that the message "good morning" is the only one he wanted because he couldn't recognize some words in the other messages. So he will always consider the message he can understand the correct one. Whether he can understand a message depends whether he knows all the words in the message. If there are more than one ways to decrypt the message into an understandable one, he will choose the lexicographically smallest one. The way to compare two messages is to compare the words of two messages one by one, and the first pair of different words in the two messages will determine the lexicographic order of them.

Isabella sends letters to Steve almost every day. As decrypting Isabella's message takes a lot of time, and Steve can wait no longer to know the content of the message, he asked you for help. Now you are given the message he received, the mask, and the list of words he already knew, can you write a program to help him decrypt it?

 
Input
The first line contains an integer T(1 <= T <= 100), indicating the number of test cases.

Each test case contains several lines.

The first line contains an even integer N(2 <= N <= 50), indicating the size of the matrix.

The following N lines each contains exactly N characters, reresenting the message matrix. The message only contains lowercase letters and periods('.'), where periods represent the white spaces.

You can assume the matrix contains at least one letter.

The followingN lines each containsN characters, representing the mask matrix. The asterisk('*') represents a hole, and period('.') otherwise. The next line contains an integer M(1 <= M <= 100), the number of words he knew.

Then the following M lines each contains a string represents a word. The words only contain lowercase letters, and its length will not exceed 20.

 
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is Isabella's message.

If Steve cannot understand the message, just print the Y as "FAIL TO DECRYPT".
 
Sample Input
3
4
o.do
.ng.
grmn
o.i.
.*..
*.*.
....
*...
2
good
morning
4
..lf
eoyv
oeou
vrer
..*.
.*..
....
*.*.
5
i
you
the
love
forever
4
.sle
s.c.
e.fs
..uu
*...
.*..
...*
..*.
1
successful
 
Sample Output
Case #1: good morning
Case #2: love you forever
Case #3: FAIL TO DECRYPT
 
Source
 
Recommend
chenyongfu
好吧,不说了,题目意思读错了,找了好长时间的错,都没找出来,其实,找到4个单词串可以首尾转,也就是有4种组和方式,很简单的模拟啊!
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAXN 55
struct node {
char map[MAXN][MAXN];
};
int n,kk;char str[4][10000],lib[10000][25],anss[10000],stemp[10000];int strnum[4];
bool strflag[4];
node change(node a)
{
int i,j,ii,k;node b;
for(i=0,ii=0;i<n;i++,ii++)
{
for(j=n-1,k=0;j>=0;j--,k++)
{
b.map[ii][k]=a.map[j][i];
}
}
return b;
}
bool find(char str[])
{
int i;
for(i=0;i<kk;i++)
{
if(strcmp(str,lib[i])==0)
return true;
}
return false;
}
int main()
{
int tcase,i,j,i2,space,tt=1;
node a,b;
scanf("%d",&tcase);
while(tcase--)
{
memset(strnum,0,sizeof(strnum));
memset(strflag,true,sizeof(strflag));
for(i=0;i<4;i++)
{
memset(str[i],0,sizeof(str[i]));
}
scanf("%d",&n);
gets(stemp);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
char c=getchar();
a.map[i][j]=c;
}
gets(stemp);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
char c=getchar();
b.map[i][j]=c;
}
gets(stemp);
}
scanf("%d",&kk);
gets(stemp);
for(i=0;i<kk;i++)
{
scanf("%s",lib[i]);
}
memset(stemp,0,sizeof(stemp));
int space=0;node primeb=b;
for(i=0;i<4;i++)
{
bool flag=true;space=0;b=primeb;
for(j=0;j<4&&flag;j++)
{
for(int ii=0;ii<n&&flag;ii++)
for(int jj=0;jj<n&&flag;jj++)
{
if(b.map[ii][jj]=='*')
{
if(a.map[ii][jj]=='.'&&space>0)
{
stemp[space++]='\0';
if(!find(stemp))
{
flag=false;
strflag[i]=false;
}
else
{
str[i][strnum[i]++]=' ';
for(i2=0;i2<=space-2;i2++)
{
str[i][strnum[i]++]=stemp[i2];
}
}
space=0;
}
if(a.map[ii][jj]!='.')
{
stemp[space++]=a.map[ii][jj];
}
}
} b=change(b);
}
if(space>0&&flag)
{
stemp[space++]='\0';
if(!find(stemp))
{
flag=false;
strflag[i]=false;
}
else
{
str[i][strnum[i]++]=' ';
for(i2=0;i2<=space-2;i2++)
{
str[i][strnum[i]++]=stemp[i2];
}
}
space=0;
}
primeb=change(primeb);
}
bool flag=true;
for(i=0;i<4;i++)
{
if(strflag[i])
{
str[i][strnum[i]++]='\0';
if(flag)
{
strcpy(anss,str[i]);
flag=false;
}
if(strcmp(anss,str[i])>0)
strcpy(anss,str[i]);
}
}
if(!flag)
printf("Case #%d:%s\n",tt++,anss);
else
printf("Case #%d: FAIL TO DECRYPT\n",tt++);
}
return 0;
}

hdu 4119 Isabella's Message的更多相关文章

  1. hdu 4119 Isabella&&num;39&semi;s Message 模拟题

    Isabella's Message Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  2. hdu 3410 Passing the Message&lpar;单调队列&rpar;

    题目链接:hdu 3410 Passing the Message 题意: 说那么多,其实就是对于每个a[i],让你找他的从左边(右边)开始找a[j]<a[i]并且a[j]=max(a[j])( ...

  3. hdu 4300 Clairewd’s message KMP应用

    Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...

  4. hdu 4300 Clairewd’s message(具体解释,扩展KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...

  5. hdu 4300 Clairewd’s message&lpar;扩展kmp&rpar;

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  6. HDU 4300 Clairewd’s message&lpar;KMP&plus;思维&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...

  7. 【HDU 4300 Clairewd’s message】

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  8. HDU - 3410 Passing the Message 单调递减栈

    Passing the Message What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flo ...

  9. hdu 4300 Clairewd’s message 字符串哈希

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. 纯JS打造比QQ空间更强大的图片浏览器-支持拖拽、缩放、过滤、缩略图等

    在线演示地址(打开网页后,点击商家图册): http://www.sport7.cn/cc/jiangnan/football5.html 先看一看效果图: 该图片浏览器实现的功能如下: 1. 鼠标滚 ...

  2. Java Thread 的使用

    Java Thread 的使用 Java Thread 的 run() 与 start() 的区别 Java Thread 的 sleep() 和 wait() 的区别   一.线程的状态 在正式学习 ...

  3. CSS3和jQuery实现的自定义美化Checkbox

    效果图: 是不是比默认的好看多了,个人的审美观应该还是可以的. 当然我们可以在这里查看DEMO演示. 接下来我们一起来看看实现这款美化版Checkbox的源代码.主要思路是利用隐藏原来的checkbo ...

  4. CentOS系统将UTC时间修改为CST时间

    1.编辑时间配置文件 # vi /etc/sysconfig/clock ZONE="Asia/Shanghai" UTC=false #设置为false,硬件时钟不于utc时间一 ...

  5. 《CSS3秘籍》(第三版)-读书笔记&lpar;2&rpar;

    第6章 文本格式化 1.  使用字体 字体font-family: 通用的字体样式: serif字体最适用于冗长的文字信息.这种字体使字母主笔画的结尾处会有一些细小的“足”. sans-serif字体 ...

  6. api-gateway实践(04)新服务网关 - 新手入门

    一.网关引擎环境 1.下载代码 2.搭建环境 3.打包部署 二.配置中心环境 1.下载代码 2.搭建环境 3.打包部署 三.创建业务实例 1.以租户身份登录配置中心,注册 group.version. ...

  7. tarjan算法(求强连通子块,缩点)

    tarjan算法求图中的强连通子图的个数. #include<iostream> #include<stack> #include<queue> #include& ...

  8. hdu 2098 分拆素数和(素数)

    分拆素数和 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. Javascript 异步处理与计时跳转

    实现计时跳转的代码: <html lang="en"> <head> <meta charset="UTF-8"> < ...

  10. &lbrack;hgoi&num;2019&sol;2&sol;16t4&rsqb;transform

    题目描述 植物学家Dustar培养出了一棵神奇的树,这棵有根树有n个节点,每个节点上都有一个数字a[i],而且这棵树的根为r节点. 这棵树非常神奇,可以随意转换根的位置,上一秒钟它的根是x节点,下一秒 ...