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的,我不想再写了= =

代码:

  1. //qscqesze
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <ctime>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <set>
  9. #include <vector>
  10. #include <sstream>
  11. #include <queue>
  12. #include <typeinfo>
  13. #include <fstream>
  14. #include <map>
  15. #include <stack>
  16. typedef long long ll;
  17. using namespace std;
  18. //freopen("D.in","r",stdin);
  19. //freopen("D.out","w",stdout);
  20. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  21. #define maxn 10001
  22. #define mod 10007
  23. #define eps 1e-9
  24. int Num;
  25. char CH[];
  26. //const int inf=0x7fffffff; //нчоч╢С
  27. const int inf=0x3f3f3f3f;
  28. /*
  29.  
  30. inline void P(int x)
  31. {
  32. Num=0;if(!x){putchar('0');puts("");return;}
  33. while(x>0)CH[++Num]=x%10,x/=10;
  34. while(Num)putchar(CH[Num--]+48);
  35. puts("");
  36. }
  37. */
  38. inline ll read()
  39. {
  40. ll x=,f=;char ch=getchar();
  41. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  42. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  43. return x*f;
  44. }
  45. inline void P(int x)
  46. {
  47. Num=;if(!x){putchar('');puts("");return;}
  48. while(x>)CH[++Num]=x%,x/=;
  49. while(Num)putchar(CH[Num--]+);
  50. puts("");
  51. }
  52. //**************************************************************************************
  53.  
  54. string s1[maxn];
  55. string s2[maxn];
  56. string s3[maxn];
  57. int n,m;
  58. string s66[maxn];
  59. int flag;
  60. int cnt;
  61. int deal(string s55)
  62. {
  63. //cout<<s55<<endl;
  64. cnt=;
  65. flag=;
  66. s66[cnt]="";
  67. for(int i=;i<s55.size();i++)
  68. {
  69. if(s55[i]=='.')
  70. continue;
  71. else
  72. {
  73. s66[cnt]+=s55[i];
  74. if(i+>=s55.size()||s55[i+]=='.')
  75. {
  76. int flag2=;
  77. for(int i=;i<m;i++)
  78. if(s66[cnt]==s3[i])
  79. flag2++;
  80. if(!flag2)
  81. flag=;
  82. if(flag==)
  83. break;
  84. cnt++;
  85. s66[cnt]="";
  86. }
  87. }
  88. }
  89. return flag;
  90. }
  91. int main()
  92. {
  93. //freopen("test.txt","r",stdin);
  94. int t=read();
  95. for(int cas=;cas<=t;cas++)
  96. {
  97. //memset(s1,0,sizeof(s1));
  98. //memset(s2,0,sizeof(s2));
  99. //memset(s3,0,sizeof(s3));
  100. n=read();
  101. for(int i=;i<n;i++)
  102. cin>>s1[i];
  103. int len=s1[].size();
  104. for(int i=;i<n;i++)
  105. cin>>s2[i];
  106. m=read();
  107. for(int i=;i<m;i++)
  108. {
  109. cin>>s3[i];
  110. }
  111. string s11,s22,s33,s44;
  112. for(int i=;i<n;i++)
  113. {
  114. for(int j=;j<n;j++)
  115. {
  116. if(s2[i][j]=='*')
  117. s11+=s1[i][j];
  118. if(s2[j][n-i-]=='*')
  119. s44+=s1[i][j];
  120. if(s2[n-i-][n-j-]=='*')
  121. s33+=s1[i][j];
  122. if(s2[n-j-][i]=='*')
  123. s22+=s1[i][j];
  124. }
  125. }
  126. string s55=s11+s22+s33+s44;
  127. deal(s55);
  128. if(!flag)
  129. {
  130. printf("Case #%d: ",cas);
  131. for(int i=;i<cnt;i++)
  132. {
  133. if(i!=cnt-)
  134. cout<<s66[i]<<" ";
  135. else
  136. cout<<s66[i];
  137. }
  138. cout<<endl;
  139. }
  140. else
  141. {
  142. s55=s22+s33+s44+s11;
  143. deal(s55);
  144. if(!flag)
  145. {
  146. printf("Case #%d: ",cas);
  147. for(int i=;i<cnt;i++)
  148. {
  149. if(i!=cnt-)
  150. cout<<s66[i]<<" ";
  151. else
  152. cout<<s66[i];
  153. }
  154. cout<<endl;
  155. }
  156. else
  157. {
  158. s55=s33+s44+s11+s22;
  159. deal(s55);
  160. if(!flag)
  161. {
  162. printf("Case #%d: ",cas);
  163. for(int i=;i<cnt;i++)
  164. {
  165. if(i!=cnt-)
  166. cout<<s66[i]<<" ";
  167. else
  168. cout<<s66[i];
  169. }
  170. cout<<endl;
  171. }
  172. else
  173. {
  174. s55=s44+s11+s22+s33;
  175. deal(s55);
  176. if(!flag)
  177. {
  178. printf("Case #%d: ",cas);
  179. for(int i=;i<cnt;i++)
  180. {
  181. if(i!=cnt-)
  182. cout<<s66[i]<<" ";
  183. else
  184. cout<<s66[i];
  185. }
  186. cout<<endl;
  187. }
  188. else
  189. {
  190. printf("Case #%d: FAIL TO DECRYPT\n",cas);
  191. }
  192. }
  193. }
  194. }
  195. }
  196. }

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. X86控制寄存器和系统地址寄存器

    80386控制寄存器和系统地址寄存器如下表所示.它们用于控制工作方式,控制分段管理机制及分页管理机制的实施. 控制寄存器 CRx BIT31 BIT30—BIT12 BIT11—BIT5 BIT4 B ...

  2. SSL handshake failed: SSL error: Key usage violation in certificate has been detected.

    sudo apt-get install libneon27-dev cd /usr/libsudo mv libneon-gnutls.so.27 libneon-gnutls.so.27.olds ...

  3. puppet practice

    目标 试验环境有两台主机(VM)构成,一台是master,一台是agent,完成以下工作: 新建用户newuser; 安装 ubuntu-cloud-keyring package,更改文件/etc/ ...

  4. Docker Commands

    Docker Commands 安装,以Ubuntu 14.04.3为例 apt-get install docker.io 注意安装之前需要更新系统 列出曾经存在的容器 docker ps -a 列 ...

  5. Jmeter命令行选项

    示例:jmeter.bat -n -j %tmp%\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%%time:~ ...

  6. [SVN技巧]代码提交中遇到的两个问题及其解决方案

    前言 SVN在使用的过程中会遇到各种各样的问题,小黑在最近的使用中,遇到如下的两个问题,这里贴出来供大家参考 问题记录 SVN在源码仓库中不存在,导致无法删除和上传 问题提示: Working cop ...

  7. u-boot中的Makefile

    在windos下,pc机上电之后,BIOS会初始化硬件配置,为内核传递参数,引导操作系统启动,并且识别C盘.D盘.等整个操作系统启动起来之后,才可以运行应用程序比如QQ.QQ音影.同理,在嵌入式Lin ...

  8. ansible报错AttributeError: module 'urllib.request' has no attribute 'HTTPSHandler'

    报错内容: TASK [activemq : extract activemq tarball] *************************************************** ...

  9. Percona XtraDB Cluster(PXC) -集群环境安装

    Percona XtraDB Cluster(PXC)   ---服务安装篇   1.测试环境搭建: Ip 角色 OS PXC-version 172.16.40.201 Node1 Redhat/C ...

  10. Java学习(基本语句,语法,变量)

    一.基本语法: public class Demo { //定义一个类 public static void main(String[] args) { //主方法,一切程序的起点 /* 在屏幕上打印 ...