Isabella's Message

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4119

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".

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".

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

HINT

题意

给你一个n*n的格子,格子里面有字母和空格,然后你拿挡板去截取字母,然后问你是否能够还原。

题解:

最多4种情况,直接模拟搞就好了

我的代码是wa的,我不想再写了= =

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 10001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s1[maxn];
string s2[maxn];
string s3[maxn];
int n,m;
string s66[maxn];
int flag;
int cnt;
int deal(string s55)
{
//cout<<s55<<endl;
cnt=;
flag=;
s66[cnt]="";
for(int i=;i<s55.size();i++)
{
if(s55[i]=='.')
continue;
else
{
s66[cnt]+=s55[i];
if(i+>=s55.size()||s55[i+]=='.')
{
int flag2=;
for(int i=;i<m;i++)
if(s66[cnt]==s3[i])
flag2++;
if(!flag2)
flag=;
if(flag==)
break;
cnt++;
s66[cnt]="";
}
}
}
return flag;
}
int main()
{
//freopen("test.txt","r",stdin);
int t=read();
for(int cas=;cas<=t;cas++)
{
//memset(s1,0,sizeof(s1));
//memset(s2,0,sizeof(s2));
//memset(s3,0,sizeof(s3));
n=read();
for(int i=;i<n;i++)
cin>>s1[i];
int len=s1[].size();
for(int i=;i<n;i++)
cin>>s2[i];
m=read();
for(int i=;i<m;i++)
{
cin>>s3[i];
}
string s11,s22,s33,s44;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(s2[i][j]=='*')
s11+=s1[i][j];
if(s2[j][n-i-]=='*')
s44+=s1[i][j];
if(s2[n-i-][n-j-]=='*')
s33+=s1[i][j];
if(s2[n-j-][i]=='*')
s22+=s1[i][j];
}
}
string s55=s11+s22+s33+s44;
deal(s55);
if(!flag)
{
printf("Case #%d: ",cas);
for(int i=;i<cnt;i++)
{
if(i!=cnt-)
cout<<s66[i]<<" ";
else
cout<<s66[i];
}
cout<<endl;
}
else
{
s55=s22+s33+s44+s11;
deal(s55);
if(!flag)
{
printf("Case #%d: ",cas);
for(int i=;i<cnt;i++)
{
if(i!=cnt-)
cout<<s66[i]<<" ";
else
cout<<s66[i];
}
cout<<endl;
}
else
{
s55=s33+s44+s11+s22;
deal(s55);
if(!flag)
{
printf("Case #%d: ",cas);
for(int i=;i<cnt;i++)
{
if(i!=cnt-)
cout<<s66[i]<<" ";
else
cout<<s66[i];
}
cout<<endl;
}
else
{
s55=s44+s11+s22+s33;
deal(s55);
if(!flag)
{
printf("Case #%d: ",cas);
for(int i=;i<cnt;i++)
{
if(i!=cnt-)
cout<<s66[i]<<" ";
else
cout<<s66[i];
}
cout<<endl;
}
else
{
printf("Case #%d: FAIL TO DECRYPT\n",cas);
}
}
}
}
}
}

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

  1. hdu 4119 Isabella's Message

    Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  3. HDU 4452 Running Rabbits (模拟题)

    题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向. 现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路. 相碰: 两只兔子在K点整(即处 ...

  4. HDU 2414 Chessboard Dance(模拟题,仅此纪念我的堕落)

    题目 模拟题也各种wa,我最近真的堕落了,,,,,智商越来越为负数了!!!!!!!! #include<stdio.h> #include<string.h> #include ...

  5. HDU 4925 Apple Tree(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...

  6. HDU 4364——Matrix operation——————【模拟题】

    Matrix operation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu 1861 游船出租(模拟题,,水)

    题意: 现有公园游船租赁处请你编写一个租船管理系统. 当游客租船时,管理员输入船号并按下S键,系统开始计时:当游客还船时,管理员输入船号并按下E键,系统结束计时. 船号为不超过100的正整数.当管理员 ...

  8. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

  9. HDU 1262 寻找素数对 模拟题

    题目描述:输入一个偶数,判断这个偶数可以由哪两个差值最小的素数相加,输出这两个素数. 题目分析:模拟题,注意的是为了提高效率,在逐个进行判断时,只要从2判断到n/2就可以了,并且最好用打表法判断素数. ...

随机推荐

  1. 深入理解Spring系列之十二:@Transactional是如何工作的

    转载 https://mp.weixin.qq.com/s/ZwhkUQF1Nun9pNrFI-3a6w 首先从说起.配置了,就必定有对应的标签解析器类,查看NamespaceHandler接口的实现 ...

  2. Codeforces 870E Points, Lines and Ready-made Titles 计数

    题目链接 题意 给定二维坐标上的\(n\)个点,过每个点可以 画一条水平线 或 画一条竖直线 或 什么都不画,并且若干条重合的直线被看做同一条.问共可能得到多少幅不同的画面? 题解 官方题解 仆の瞎扯 ...

  3. thinkphp对数据库的增删改查(查询构造器)

  4. docker安装总结 linux红帽系列

    由于Docker限制分为两个版本CE和EE,所以之前yum里面的docker是老版本,需要先进行卸载,现在的包名叫做docker-ce yum remove docker docker-common ...

  5. 72.xilinx vivado zynq vdma仿真及应用详解(一)

    很多人用zynq平台做视频图像开发,但是对vdma了解比较少,上手起来稍微有些困难,我针对这一现象,做了一个基于vivado和modelsim的仿真和应用测试工程,并写篇文章做些介绍,希望能对大家有帮 ...

  6. SSO单点登录的发展由来以及实现原理【转】

    单点登录以及权限,在很早之前都有写过,不过都比较简单,今天就具体说一下,以及下一步要做的 1.web单系统应用 早期我们开发web应用都是所有的包放在一起打成一个war包放入tomcat容器来运行的, ...

  7. BZOJ 2049: [Sdoi2008]Cave 洞穴勘测——LCT

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2049 省选之前来切一道数据结构模板题. 题意 这是一道模板题. N个点,M次操作,每次加边/ ...

  8. Python3中字符串的编码与解码以及编码之间转换(decode、encode)

    一.编码 二.编码与解码 Python3中对py文件的默认编码是urf-8.但是字符串的编码是Unicode. 由于Unicode采用32位4个字节来表示一个字符,存储和传输太浪费资源,所以传输和存储 ...

  9. python 随机字符串

    pip3 install pillow 读取硬盘中的文件,在页面显示 f = open('static/imgs/yj.png','rb') data = f.read() f.close() ret ...

  10. TGPPen 宽度的理解

    procedure TForm4.Button1Click(Sender: TObject); var g: TGPGraphics; p: TGPPen; begin g := TGPGraphic ...