题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1009

题目大意:给你三个转换轮,只有当第一个转换轮转动一圈后第二个才会转,当第二个转动一圈后第三个才会转。转换轮的意思是我按动一个按钮,显示器经过转换轮的转换显示另外一个字母。每按下一个按钮,第一个转换轮都会转动一次。

叉姐说得好,多学习一下思维方法,有些问题都是能够很高效率的想出来的。脑洞什么的全是骗人的。

注意看这张图:

中间转动轮的点, 左右两边是一一对应的。

也就是说,无论转动轮怎么转,都能把左边的keyboard和右边的display一一对应上,不重不漏。

那么,我们给rotor左边的接口依次标号1,2,3,4,5,6 并且根据第一个状态读出对应关系。即1,-1,1,2,0,-3

经过对应关系,我们把keyboard上的标为A集合{a,b,c,d,e,f} 经过对应关系B {1,-1,1,2,0,-3}, 得到 {a+1,b-1,c+1,d+2,e+0,f-3} => {b,a,d,f,e,c}

然后再经过一层对应关系C {0,0,1,1,1,-3} => {b,a,e,f,c,d} ,注意第二个关系是把a+0,b+0,c+1,d+1,f+1,e-3,也就是说不管上一个映射怎么变,这一个还是对abcdef进行映射。

那么,这就可以列出来转移映射关系式了: cc[i] = tmp[i]+r[tmp[i]];

再加上偏移:cc[i] = tmp[i]+r[((tmp[i]-st)%m+m)%m]

再对整个做负数处理:cc[i] = ((tmp[i]+r[((tmp[i]-st)%m+m)%m])%m+m)%m

我就是这里没想好,卡了好久。

到这里,题目就做了一大半。

接下来,我们发现A经过三次映射到了D

那么也就是说我们可以把中间的关系合并起来  A -> D。

表示成f(A) = D

那么求反函数即可g(D) = A

接下来就是链表的事情咯。

 #include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <cmath>
#include <numeric>
#include <ctime>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define PB push_back
#define MP make_pair
#define SZ size()
#define CL clear()
#define AA first
#define BB second
#define EPS 1e-8
#define ZERO(x) memset((x),0,sizeof(x))
const int INF = ~0U>>;
const double PI = acos(-1.0); int m,n;
char r[][];
int e[][];
const int MAX_N = **;
int tmp[]; struct CircularNode{
int lst[];
int num;
CircularNode *next;
CircularNode(int n){
memset(lst,,sizeof(lst));
num = n;
next = NULL;
}
~CircularNode(){
if( next ){
delete next;
next = NULL;
}
}
}; struct CircularList{
CircularNode *rt,*cur;
~CircularList(){
delete rt;
}
CircularList(){
rt = NULL;
}
void push_back(int a[],int m){
if( !rt ) {
rt = new CircularNode(m);
cur = rt;
} else {
cur->next = new CircularNode(m);
cur = cur->next;
} for(int j=;j<m;j++){
cur->lst[a[j]] = j;
}
}
}; void mapping(int *r,int st){
int cc[];
for(int i=;i<m;i++){
cc[i] = ((tmp[i]+r[(tmp[i]-st+m)%m])%m+m)%m;
}
for(int i=;i<m;i++){
tmp[i] = cc[i];
}
} int main(){
int kase = ;
while(scanf("%d",&m),m){
if(kase!=) puts("");
printf("Enigma %d:\n",kase++);
for(int i=;i<;i++) scanf("%s",r[i]);
for(int i=;i<;i++){
for(int j=;j<m;j++){
e[i][j] = r[i][j] - 'A' - j;
// printf("%d ",e[i][j]);
}
// puts("");
} CircularList *aCircularList = new CircularList; for(int st1=;st1<m;st1++){
for(int st2=;st2<m;st2++){
for(int st3=;st3<m;st3++){
for(int i=;i<m;i++) tmp[i] = i;
mapping(e[],st3);
// for(int i=0;i<m;i++) printf("%d ",tmp[i]); puts("");
mapping(e[],st2);
// for(int i=0;i<m;i++) printf("%d ",tmp[i]); puts("");
mapping(e[],st1);
// for(int i=0;i<m;i++) printf("%d ",tmp[i]); puts("");
aCircularList->push_back(tmp,m);
// for(int i=0;i<m;i++){
// printf("%d ",aCircularList->cur->lst[i]);
// }
// puts("");
}
// exit(0);
}
} scanf("%d",&n);
getchar();
int kase = ;
while(n--){
CircularNode *p = aCircularList->rt;
char c;
while( (c=getchar())!='\n' ){
// printf("%d\n",p->lst[c-'A']);
putchar('a'+p->lst[c-'A']);
p = p->next;
if(!p) p = aCircularList->rt;
}
puts("");
} delete aCircularList;
}
return ;
} /*
6
FDBCAE
ABDEFC
CDAFEB
1
ACE
*/

[ZOJ 1009] Enigma (模拟)的更多相关文章

  1. 1009 Enigma

    本题的重点是理解清楚题意并能代码模拟.形式是二战德国密码机,和数据结构.算法联系较少. #include <stdio.h> #include <string.h> int m ...

  2. Enigma模拟-Python

    设计思想 Enigma机的机械结构: 键盘:加密人员通过键盘进行输入 转子:Enigma机上一般装有至少3个转轮.每个转轮有代表26个字母的触头和触点,触点和触头在转轮内部有导线相连(一个转轮相当于一 ...

  3. A - Jugs ZOJ - 1005 (模拟)

    题目链接:https://cn.vjudge.net/contest/281037#problem/A 题目大意:给你a,b,n.a代表第一个杯子的容量,b代表第二个杯子的容量,然后一共有6种操作.让 ...

  4. ZOJ 2610 Puzzle 模拟

    大模拟:枚举6个方向.检查每一个0是否能移动 Puzzle Time Limit: 2 Seconds      Memory Limit: 65536 KB Little Georgie likes ...

  5. Capture the Flag ZOJ - 3879(模拟题)

    In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...

  6. ZOJ 3705 Applications 模拟

    #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include< ...

  7. ZOJ 3652 Maze 模拟,bfs,读题 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4842 要注意题目中两点: 1.在踏入妖怪控制的区域那一刹那,先减行动力,然后才 ...

  8. ZOJ 1122 Clock(模拟)

    Clock Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given a standard 12-hour clock with ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. CSS之background属性

    css背景是个很有意思的东西,可设置 背景色:background-color 背景图:backgoround-image 背景图显示相对位置:background-position,正数图片往右下移 ...

  2. 项目中提示找不到class,跟命名规则有关系RulesConfigDao

    项目中提示找不到class,跟命名规则有关系RulesConfigDao,而非Mapper!

  3. 数字根(digital root)

    来源:LeetCode 258  Add Dights Question:Given a non-negative integer  num , repeatedly add all its digi ...

  4. HBase(三): Azure HDInsigt HBase表数据导入本地HBase

    目录: hdfs 命令操作本地 hbase Azure HDInsight HBase表数据导入本地 hbase hdfs命令操作本地hbase: 参见  HDP2.4安装(五):集群及组件安装 , ...

  5. Ajax请求在IE和Google Chrome中可以响应,在Firefox中无法响应

    在工作中碰到这么一个问题,发送ajax请求,在IE和chrome中可以正常的响应,但是在Firefox中无法响应,代码如下: JS代码: function Sure(obj) { var statu ...

  6. 创建UIImage的两种方法

    1. UIImage *img = [UIImage imageNamed:@"imageName"]; 2. NSString *imageFilePath = [[NSBund ...

  7. LeetCode "Count of Smaller Number After Self"

    Almost identical to LintCode "Count of Smaller Number before Self". Corner case needs to b ...

  8. activiti自定义流程之自定义表单(一):环境配置

    先补充说一下自定义流程整个的思路,自定义流程的目的就是为了让一套代码解决多种业务流程,比如请假单.报销单.采购单.协作单等等,用户自己来设计流程图. 这里要涉及到这样几个基本问题,一是不同的业务需求, ...

  9. [实变函数]3.1 外测度 (outer measure)

    1 并不是所有的集合都可求测度. 我们的想法是先对 $\bbR^n$ 中的任一集合定义一个``外 测度'' (outer measure), 然后再加上适当的条件 (Caratheodory 条件), ...

  10. 转--2014年最新810多套android源码2.46GB免费一次性打包下载

    转载自:http://www.eoeandroid.com/thread-497046-1-1.html 感谢该博客主人无私奉献~~ 下面的源码是从今年3月份开始不断整理源码区和其他网站上的安卓例子源 ...