POJ1026 Cipher(置换的幂运算)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 21436 | Accepted: 5891 |
Description
The length of the message is always less or equal than n. If the message is shorter than n, then spaces are added to the end of the message to get the message with the length n.
Help Alice and Bob and write program which reads the key and then a sequence of pairs consisting of k and message to be encoded k times and produces a list of encoded messages.
Input
Output
Sample Input
10
4 5 3 7 2 8 1 6 10 9
1 Hello Bob
1995 CERC
0
0
Sample Output
BolHeol b
C RCE 置换的幂运算也可以用快速幂来做 代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAXN 205
int a[MAXN];
int n;
void zh(int* a,int *b)
{
int temp[MAXN];
int temp1[MAXN];
int i;
for(i=;i<=n;i++)
{
temp[i]=a[i];
temp1[i]=b[i];
}
for(i=;i<=n;i++)
a[i]=temp1[temp[i]];
}
void solve(int k,int *re)
{
int i;
int ans[MAXN];
int temp[MAXN];
for(i=;i<=n;i++)
{
temp[i]=a[i];
ans[i]=i;
}
while(k)
{
if(k&)
zh(ans,temp);
zh(temp,temp);
k>>=;
}
for(i=;i<=n;i++)
{
re[ans[i]]=i;
}
}
int main()
{
int k;
int i;
char str[MAXN];
int re[MAXN];
int len;
int cnt;
char ch;
while(scanf("%d",&n))
{
if(n==)
break;
for(i=;i<=n;i++)
scanf("%d",&a[i]);
while(scanf("%d",&k))
{
if(k==)
break;
getchar();
memset(str,' ',sizeof(str));
len=;
while((ch=getchar())!='\n')
str[len++]=ch;
solve(k,re);
cnt=;
for(i=;i<=n;i++)
{
printf("%c",str[re[i]-]);
if(re[i]-<len)
cnt++;
}
printf("\n");
}
printf("\n");
}
return ;
}
POJ1026 Cipher(置换的幂运算)的更多相关文章
- 组合数学 - 置换群的幂运算 --- poj CARDS (洗牌机)
CARDS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1448 Accepted: 773 Description ...
- poj 3128 Leonardo's Notebook(置换的幂)
http://poj.org/problem?id=3128 大致题意:输入一串含26个大写字母的字符串,能够把它看做一个置换.推断这个置换是否是某个置换的平方. 思路:具体解释可參考url=ihxG ...
- poj 3128 Leonardo's Notebook (置换群的整幂运算)
题意:给你一个置换P,问是否存在一个置换M,使M^2=P 思路:资料参考 <置换群快速幂运算研究与探讨> https://wenku.baidu.com/view/0bff6b1c6bd9 ...
- 迭代加深搜索 codevs 2541 幂运算
codevs 2541 幂运算 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出 ...
- 算数运算符: + - * / //(地板除) %(取余) **(幂运算) / 比较运算符 > < >= <= == !=
# ### python运算符 #(1) 算数运算符: + - * / //(地板除) %(取余) **(幂运算) var1 = 5 var2 = 8 # +res = var1 + var2 pri ...
- 求幂运算、多项式乘法及Horner法则的应用
一,两种不同的求幂运算 求解x^n(x 的 n 次方) ①使用递归,代码如下: private static long pow(int x, int n){ if(n == 0) return 1; ...
- LeetCode 50 Pow(x, n) (实现幂运算)
题目链接:https://leetcode.com/problems/powx-n/?tab=Description Problem:实现幂运算即 pow(x,n) 设形式为pow(x,n) ...
- Python3基础 ** 幂运算 // 整除运算
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 《挑战程序设计竞赛》2.6 数学问题-快速幂运算 POJ1995
POJ3641 此题应归类为素数. POJ1995 http://poj.org/problem?id=1995 题意 求(A1^B1+A2^B2+ - +AH^BH)mod M. 思路 标准快速幂运 ...
随机推荐
- 利用html5、websocket和opencv实现人脸检测
最近学习人脸识别相关的东西,在MFC下使用OpenCV做了一个简单的应用.训练需要较多的数据,windows应用程序终究还是不方便,于是想着做成CS模式:检测识别都放在服务器端,视频获取和显示都放在网 ...
- Newtonsoft.Json 版本冲突解决
在做asp.net MVC 开发时,因为引用的dll 中使用了更高版本的 Newtonsoft.Json ,导致运行时发生错误, 查资料说是因为webApi使用了Newtonsoft.Json 导致了 ...
- C# 通过反射获取扩展方法
注意,扩展方法本质上是静态方法,所以拿到MethodInfo时,应该这么调用 methodInfo.Invoke(null, new object[]{params}) static IEnumera ...
- strtok源码 bitset 空间压缩
源代码里有一段: unsigned char map[32]; /* Clear control map */ for (count = 0; count < 32; count++) map[ ...
- jq冒泡之——点击其他地方隐藏
e.stopPropagetion(); <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- ssh 使用
svn 删除所有的 .svn文件 find . -name .svn -type d -exec rm -fr {} \; linux之cp/scp命令+scp命令详解 注意:本篇以后设涉及到的@后面 ...
- html5+css3+jquery完成响应式布局
响应式布局,流体布局,自适应布局,静态布局等等,这是移动设备的飞速发展,前端人员不得不跟上潮流的一个方向.实际上各种设备尺寸,分辨率大都不同,真的适应各种设备依旧是不现实的,首先是浏览器差异化,让我们 ...
- Vue - 事件绑定
1.内联方式: A:将事件处理器绑定到一个方法中,以下所有事件都以click事件作为案例 注意:内联方式下事件处理器只能绑定一个方法,要是想要绑定多个方法,依旧还是使用js中的addEventList ...
- URAL 2089 Experienced coach Twosat
Description Misha trains several ACM teams at the university. He is an experienced coach, and he doe ...
- Haxe是何物?
最近对haxe很感兴趣,用一种语言统一所有的语言和平台,野心很大. 详细的介绍园子里已有大神发过,地址在这里:http://www.cnblogs.com/xiaotie/archive/2012/0 ...