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. 思路 标准快速幂运 ...
随机推荐
- 第三天--html区块
<!Doctype html><html> <head> <meta charset="utf-8"> ...
- EF jsonignore
页面单独指定不循环引用 [JsonIgnore] Newtonsoft.Json.JsonSerializerSettings jsSettings = new Newtonsoft.Json.Jso ...
- linux的相关指令命令
ls:查看当前所在的目录 whoami:查看当前所在的用户名 who:(查看所有的正在使用的用户名) id:唯一的识别编号(组所在的识别编号) uname -a:显示当前操作系统的版本 cd:切换工 ...
- webstorm添加*.vue文件代码提醒支持webstorm支持es6vue里支持es6写法
本文转自:http://www.lred.me/2016/01/07/webstorm%E6%B7%BB%E5%8A%A0-vue%E6%96%87%E4%BB%B6%E6%94%AF%E6%8C%8 ...
- jquery 替换img 属性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 【笔记】mysql两条数据的某个属性值互换
update groupuser as g1 join groupuser as g2 on (g1.user_id=1 and g2.user_id = 2) or(g1.user_id = 2 a ...
- struts 2 时间控件
在使用struts2框架时,为我们提供了时间选择器控件:datetimepicker.但是在使用过程中会出现一些问题,主要就是struts2版本更新时做了一些修改.在struts2.0时,使用< ...
- 比较完整的WebView的用法
WebView, WebChromeClient和WebViewClient加载网页基本用法 webview是android中的浏览器控件,在一些手机应用中常会用到b/s模式去开发应用,这时webvi ...
- eclipse 创建maven web项目
参考:http://www.cnblogs.com/hongwz/p/5456616.html eclipse 创建maven web项目
- [原创]Centos7 从零整合LNMP一体包
按照前几章配置好后,我们就可以把这些工具打包啦.生成LNMP一体包. # export LD_LIBRARY_PATH=/package/libmemcached/lib:$LD_LIBRARY_PA ...