标签:
Time Limit: 20 Sec Memory Limit: 256 MB
http://acm.hdu.edu.cn/showproblem.php?pid=4119
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".
题意
给你一个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[20]; //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=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } 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(""); } //************************************************************************************** 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=0; flag=0; s66[cnt]=""; for(int i=0;i<s55.size();i++) { if(s55[i]==‘.‘) continue; else { s66[cnt]+=s55[i]; if(i+1>=s55.size()||s55[i+1]==‘.‘) { int flag2=0; for(int i=0;i<m;i++) if(s66[cnt]==s3[i]) flag2++; if(!flag2) flag=1; if(flag==1) break; cnt++; s66[cnt]=""; } } } return flag; } int main() { //freopen("test.txt","r",stdin); int t=read(); for(int cas=1;cas<=t;cas++) { //memset(s1,0,sizeof(s1)); //memset(s2,0,sizeof(s2)); //memset(s3,0,sizeof(s3)); n=read(); for(int i=0;i<n;i++) cin>>s1[i]; int len=s1[0].size(); for(int i=0;i<n;i++) cin>>s2[i]; m=read(); for(int i=0;i<m;i++) { cin>>s3[i]; } string s11,s22,s33,s44; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(s2[i][j]==‘*‘) s11+=s1[i][j]; if(s2[j][n-i-1]==‘*‘) s44+=s1[i][j]; if(s2[n-i-1][n-j-1]==‘*‘) s33+=s1[i][j]; if(s2[n-j-1][i]==‘*‘) s22+=s1[i][j]; } } string s55=s11+s22+s33+s44; deal(s55); if(!flag) { printf("Case #%d: ",cas); for(int i=0;i<cnt;i++) { if(i!=cnt-1) 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=0;i<cnt;i++) { if(i!=cnt-1) 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=0;i<cnt;i++) { if(i!=cnt-1) 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=0;i<cnt;i++) { if(i!=cnt-1) cout<<s66[i]<<" "; else cout<<s66[i]; } cout<<endl; } else { printf("Case #%d: FAIL TO DECRYPT\n",cas); } } } } } }
hdu 4119 Isabella's Message 模拟题
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4526249.html