The Imitation Game
《The Imitation Game》是一部非常好的电影,讲述了人工智能之父——阿兰图灵的传奇一生。
重点讲述了他通过破译德国的通讯密码缩短了二战的持续时间,因而拯救了无数生命的伟大事迹。
强烈推荐大家去看一看,这可是豆瓣评分8.6的好片啊!
另外,《The Imitation Game》也是当年图灵发表的关于他对人工智能看法的论文。链接在此
德国当时的加密方式叫Enigma,具体是怎样的加密机制呢?图灵面临了怎样的挑战呢?
POJ 1449给了我们一次亲身体验破解Enigma的机会。
代码如下:
#include <cstdio>
#include <cstring>
using namespace std; #define D(x) int f[][];
int g[][];
int state[];
int cipher[];
int plain[];
int len;
int *mark[];
int mark_num;
bool ok;
int power[] = {, , * , * * }; int get_next(int a[])
{
char st[];
scanf("%s", st);
for (int i = ; st[i]; i++)
{
if (st[i] == '?')
{
a[i] = -;
mark[mark_num++] = &a[i];
continue;
}
a[i] = st[i] - 'a';
}
return strlen(st);
} void input()
{
mark_num = ;
for (int i = ; i < ; i++)
{
get_next(f[i]);
}
get_next(state);
len = get_next(plain);
get_next(cipher);
} void output()
{
for (int i = ; i < len; i++)
{
putchar(plain[i] + 'a');
}
puts("");
} int encrypt(int a, int pos)
{
int temp = f[][a];
int cur_state[];
int delta[]; for (int i = ; i < ; i++)
{
cur_state[i] = state[i] + pos / power[i];
cur_state[i] = (cur_state[i] + ) % ;
}
delta[] = cur_state[];
for (int i = ; i < ; i++)
{
delta[i] = (cur_state[i] - cur_state[i - ] + ) % ;
} for (int i = ; i < ; i++)
{
temp = f[i][(temp + delta[i] + ) % ];
} for (int i = ; i >= ; i--)
{
temp = g[i][(temp - delta[i + ] + ) % ];
} temp = g[][(temp - delta[] + ) % ];
return temp;
} bool check()
{
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
g[i][f[i][j]] = j;
}
} for (int i = ; i < len; i++)
{
if (encrypt(plain[i], i) != cipher[i])
{
return false;
}
}
return true;
} void dfs(int step)
{
if (ok)
{
return;
}
if (step == mark_num)
{
if (check())
{
ok = true;
output();
}
return;
}
for (int i = ; i < ; i++)
{
*mark[step] = i;
dfs(step + );
}
} void test(char a, int b)
{
check();
printf("%c %c\n", a, encrypt(a - 'a', b) + 'a');
} int main()
{
int t;
scanf("%d", &t);
for (int i = ; i <= t; i++)
{
printf("Scenario #%d:\n", i);
input();
ok = false;
dfs();
D(test('a', ));
puts("");
}
return ;
}
The Imitation Game的更多相关文章
- 深度学习课程笔记(七):模仿学习(imitation learning)
深度学习课程笔记(七):模仿学习(imitation learning) 2017.12.10 本文所涉及到的 模仿学习,则是从给定的展示中进行学习.机器在这个过程中,也和环境进行交互,但是,并没有显 ...
- #英文#品读中国城市个性——最好的和最坏的&当东方遇到西方
冒险家的乐园 a playground of risk 实现发财梦 realize one's dreams of wealth 道德沦丧,堕落 moral deprivation 租界 foreig ...
- Unix及类Unix系统文本编辑器的介绍
概述 Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.VIM是纯粹的自由软件. Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Em ...
- iOS开发之开源项目链接
1. Coding iOS 客户端 Coding官方客户端. 笔者强烈推荐的值得学习的完整APP.GitHub - Coding/Coding-iOS: Coding iOS 客户端源代码 2. OS ...
- AssetBundle loading failed because.....已解决
http://blog.csdn.net/ldghd/article/details/9632455 ***************************** 一 ******* ...
- 【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。
There are many kinds of testing which really made me confused. To be honest, I've never heard of som ...
- 深度|OpenAI 首批研究成果聚焦无监督学习,生成模型如何高效的理解世界(附论文)
本文经机器之心(微信公众号:almosthuman2014)授权转载,禁止二次转载,原文. 选自 Open AI 作者:ANDREJ KARPATHY, PIETER ABBEEL, GREG BRO ...
- vim深入研究
About VIM--Unix及类Unix系统文本编辑器 Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.VIM是纯粹的自由软件. Vim普遍被推崇 ...
- GitHub 上有哪些完整的 iOS-App 源码值得参考?
1. Coding iOS 客户端 Coding官方客户端. 笔者强烈推荐的值得学习的完整APP.GitHub - Coding/Coding-iOS: Coding iOS 客户端源代码 2. OS ...
随机推荐
- gradle providedCompile 与compile区别
Gradle compile: 如果你的jar包/依赖代码 在编译的时候需要依赖,在运行的时候也需要,那么就用compile例如 : compile 'org.springframework.boot ...
- 使用BeanNameAutoProxyCreator实现spring的自动代理
提到代理,我们可以使用ProxyBeanFactory,并配置proxyInterfaces,target和interceptorNames实现,但如果需要代理的bean很多,无疑会对spring配置 ...
- _fastcall
* 1楼 __fastcall具体含义 在C语言中,假设我们有这样的一个函数: int function(int a,int b) 调用时只要用result = function(1,2)这样的方式就 ...
- vim关于 引号和 括号的 高效操作-很好很强大的!
http://blog.csdn.net/bigshady/article/details/6019963 对括号匹配, 进行跳转, 使用的是%. 匹配的括号, 都会被高亮显示, 但是: 根据光标的 ...
- git SSH keys
An SSH key allows you to establish a secure connection between your computer and GitLab. Before gene ...
- php打印出来金字塔
/* 空格数($k): 第几($i)层 所以:$k+$i=$m $k=$m-$i * * 3--- ...
- UI第四节——UIImageView详解
- (void)viewDidLoad { // super调用是必须的 [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@&quo ...
- hash-1.hash表和hash算法
1.hash表 哈希表,也叫散列表,是根据关键码(Key)而直接访问的数据结构,也就是它把Key映射到表中一个位置来访问记录,即,把key计算成hashcode,把hashcode存到表中.这个把ke ...
- MySQL Python教程(1)
首先对于数据库的基本操作要有一定基础,其次了解Python的基础语法. 建议先阅读MysqL中文教程http://doc.mysql.cn/mysql5/refman-5.1-zh.html-chap ...
- WordPress文章浏览历史插件
选自:http://www.ludou.org/wordpress-recently-viewed.html 最近有很多网友问我,露兜博客右边栏底部的 您刚刚看过 栏目是怎么实现.其实我也是参考的这篇 ...