【Isabella Message】 【SPOJ - ISAB】【模拟】【矩阵的旋转】
思路
题目链接
题意:题目中先给了一个N阶矩阵样子的字符,后给了一个mask,然后又给出你应该认识的一些单词,最后是让你输出最终字典序最小的一句话。
思路:根据题目要求模拟即可。这里会用到stringstream,学习一下。不过个人觉得比较重要的是矩阵旋转部分,下面附这一块的代码。
void zhuan()
{
char temp[maxn][maxn];
memset(temp, 0, sizeof(temp)); //临时数组
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
temp[i][j] = mask[N-j-1][i]; //这一块当成结论记住吧
}
}
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
mask[i][j] = temp[i][j];
}
AC代码
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<sstream>
using namespace std;
int T, N, M;
const int maxn = 50 + 10;
char s[maxn][maxn], mask[maxn][maxn];
string words[maxn*2];
map<string, int> word;
vector<string> standard;
void zhuan()
{
char temp[maxn][maxn];
memset(temp, 0, sizeof(temp));
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
temp[i][j] = mask[N-j-1][i];
}
}
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
mask[i][j] = temp[i][j];
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> T;
for(int t = 1; t <= T; t++)
{
memset(s, 0, sizeof(s));
memset(mask, 0, sizeof(mask));
cin >> N;
for(int i = 0; i < N; i++)
scanf("%s", s[i]);
for(int i = 0; i < N; i++)
scanf("%s", mask[i]);
cin >> M;
word.clear();
for(int i = 0; i < M; i++)
{
cin >> words[i];
word[words[i]] = 1;
}
standard.clear();
string tmmp[4];
for(int ans = 0; ans < 4; ans++)
{
tmmp[ans] = "";
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if(mask[i][j] == '*')
{
if(s[i][j] != '.')
tmmp[ans] += s[i][j];
else
tmmp[ans] += " ";
}
}
}
zhuan();
}
string tmp[4];
tmp[0] = tmmp[0] + tmmp[1] + tmmp[2] + tmmp[3];
tmp[1] = tmmp[1] + tmmp[2] + tmmp[3] + tmmp[0];
tmp[2] = tmmp[2] + tmmp[3] + tmmp[0] + tmmp[1];
tmp[3] = tmmp[3] + tmmp[0] + tmmp[1] + tmmp[2];
for(int ans = 0; ans < 4; ans++)
{
int _front = 0, _back = tmp[ans].size();
for(int i = 0; i < tmp[ans].size(); i++)
{
if(tmp[ans][i] == ' ')
_front++;
else
break;
}
for(int j = tmp[ans].size() - 1; j >= 0; j--)
{
if(tmp[ans][j] == ' ')
--_back;
else
break;
}
string temp = "";
for(int i = _front; i < _back; i++)
temp += tmp[ans][i];
//cout << "temp =" << temp << "\\" << endl;
string table[maxn*2];
stringstream ss(temp);
int cnt = 0;
while(ss >> table[cnt])
{
cnt++;
}
int flag = 0;
for(int i = 0; i < cnt; i++)
{
if(word[table[i]])
continue;
else
{
flag = 1;
break;
}
}
if(!flag)
standard.push_back(temp);
}
if(!standard.empty())
{
sort(standard.begin(), standard.end());
cout << "Case #" << t << ": " << standard[0] << endl;
}
else
cout << "Case #" << t << ": " << "FAIL TO DECRYPT" << endl;
}
}
【Isabella Message】 【SPOJ - ISAB】【模拟】【矩阵的旋转】的更多相关文章
- Leetcode 566. Reshape the Matrix 矩阵变形(数组,模拟,矩阵操作)
Leetcode 566. Reshape the Matrix 矩阵变形(数组,模拟,矩阵操作) 题目描述 在MATLAB中,reshape是一个非常有用的函数,它可以将矩阵变为另一种形状且保持数据 ...
- N*N矩阵的旋转 不开辟新空间
/* N*N矩阵的旋转 不开辟新空间 programmer:qpz time:2014-11-09 */ #include <iostream> using namespace std; ...
- 2018.10.02 NOIP模拟 矩阵分组(二分答案)
传送门 考场上并不会写二分的check函数,下来看了看题解发现真是妙极. 不难想到每次直接从四个角各按阶梯状拓展出合法区域A,再检验B是否合法就行了.(然而考场上写的弃疗了) 于是题解用了一些小技巧优 ...
- [luoguP2129] L国的战斗续之多路出击(模拟 || 矩阵)
传送门 1.模拟 easy #include <cstdio> #define N 500001 int n, m; int X[N], Y[N], x[N], y[N], a = 1, ...
- LeetCode48, 如何让矩阵原地旋转90度
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode第29篇,我们来看一道简单的矩阵旋转问题. 题意 题目的要求很简单,给定一个二维方形矩阵,要求返回矩阵旋转90度之后的 ...
- POJ 2246 Matrix Chain Multiplication(结构体+栈+模拟+矩阵相乘)
题意:给出矩阵相乘的表达式,让你计算需要的相乘次数,如果不能相乘,则输出error. 思路: 参考的网站连接:http://blog.csdn.net/wangjian8006/article/det ...
- POJ.2774.Long Long Message/SPOJ.1811.LCS(后缀数组 倍增)
题目链接 POJ2774 SPOJ1811 LCS - Longest Common Substring 比后缀自动机慢好多(废话→_→). \(Description\) 求两个字符串最长公共子串 ...
- POJ.2774.Long Long Message/SPOJ.1811.LCS(后缀自动机)
题目链接 POJ2774 SPOJ1811 LCS - Longest Common Substring 确实比后缀数组快多了(废话→_→). \(Description\) 求两个字符串最长公共子串 ...
- SPOJ:Fibonacci Polynomial(矩阵递推&前缀和)
Problem description. The Fibonacci numbers defined as f(n) = f(n-1) + f(n-2) where f0 = 0 and f1 = 1 ...
随机推荐
- Linux系统-CENTOS7界面美化
前期准备: 在美化前,我们先安装一个扩展源. yum install -y epel-release 然后安装字体包 yum -y install liberation-mono-fonts 安装gn ...
- Mllib数据类型(密集向量和稀疏向量)
1.局部向量 Mllib支持2种局部向量类型:密集向量(dense)和稀疏向量(sparse). 密集向量由double类型的数组支持,而稀疏向量则由两个平行数组支持. example: 向量(5.2 ...
- py+selenium运行时报错Can not connect to the Service IEDriverServer.exe
问题: 运行用例时,出现报错(host文件已加入127.0.0.1 localhost): raise WebDriverException("Can not connect to the ...
- mvc区分页面内请求判断是否是Html.action或Html.RenderAction请求
ControllerContext.IsChildAction 来判断,如果用Html.Action或Html.RenderAction方法,这个属性返回true,否则返回false
- <a>标签 IOS 安卓 亲测有效
一.普通链接 <a href="http://www.baidu.com">百度</a> 二.邮件链接 1.标签最简式 <a href="m ...
- 简单的量子算法(一):Hadamard 变换、Parity Problem
Hadamard Transform Hadamard 变换在量子逻辑门中提过,只不过那时是单量子的Hadamard门,负责把\(|1\rangle\)变成\(|-\rangle\),\(|0\ran ...
- 个人用户永久免费,可自动升级版Excel插件,使用VSTO开发,Excel催化剂安装过程详解及安装失败解决方法
因Excel催化剂用了VSTO的开发技术,并且为了最好的用户体验,用了Clickonce的布署方式(无需人工干预自动更新,让用户使用如浏览器访问网站一般,永远是最新的内容和功能).对安装过程有一定的难 ...
- sql注入篇1
一.前言 学习了感觉很久的渗透,总结一下sql注入,系统整理一下sql注入思路. 二.关于sql注入 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到 ...
- 跟着大彬读源码 - Redis 6 - 对象和数据类型(下)
继续撸我们的对象和数据类型. 上节我们一起认识了字符串和列表,接下来还有哈希.集合和有序集合. 1 哈希对象 哈希对象的可选编码分别是:ziplist 和 hashtable. 1.1 ziplist ...
- SSM-员工管理系统Demo---带分页和校验(含源码)
页面展示: 前端JSP: <%@ page language="java" contentType="text/html; charset=UTF-8" ...