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. 思路 标准快速幂运 ...
随机推荐
- STM32F412应用开发笔记之二:基本GPIO控制
NUCLEO-F412ZG板子上的元器件并没有完全焊接,除去ST-LINK部分和电源部分后,还有用一个USB主机接口,三个LED灯和两个按钮,不过很多功能引脚都已经引到了插针.查看原理图可发现,由原理 ...
- C++处理Json串——jsoncpp库
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,和xml类似,本文主要对VS2008中使用Jsoncpp解析json的方法做一下记录.Jsoncpp是个跨 ...
- Riemann映射定理
单复变函数几何理论最高的成就我想应该属于Riemann映射定理吧! Riemann映射定理:$\mathbb C$中任意边界多余一个点的单连通域$D$都与单位圆盘$B(0,1)$等价,即存在着$D$上 ...
- mysql安装
什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库.简单来说是本身可视为电子化的文件柜--存储电子文件的处所,用户可以对文件中的数据进行新增.截取.更新.删除等操作. ...
- oracle sql 执行计划分析
转自http://itindex.net/detail/45962-oracle-sql-%E8%AE%A1%E5%88%92 一.首先创建表 SQL> show user USER is &q ...
- 关于Knockout的开始
最近看了汤姆大叔的Knockout,感到MVVM的神奇,也许这就是以后编程的方式,最直观的感觉就是层次更分明了. 绑定,模型转换,监控,在我来说,这算是编程上的一个转变,在以后我做不定期的更新一些MV ...
- mysql优化笔记之分页
过年闲得蛋疼,于是看看mysql优化,看了网上好多关于分页的优化方法,但是呢,我亲自试上一把的时候,没有出现他们说的现象...难道是我的机器问题么? 下面看看我的实践记录,希望看到的加入进来交流一下O ...
- 【校验】TCP和UDP的校验和
一开始,私以为校验和只是简单的求和得到的结果,后来在TCP和UDP里面看到使用的校验和方式有点奇怪--二进制反码(循环进位)求和. 人类的认知过程必将从简单到复杂,看下这个二进制反码循环求和是啥子意思 ...
- HDU5977 Garden of Eden(树的点分治)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...
- [转]ORACLE中Like与Instr模糊查询性能大比拼
instr(title,'手册')>0 相当于 title like '%手册%' instr(title,'手册')=1 相当于 title like '手册%' instr(titl ...