当前位置:网站首页>POJ 1026 Cipher (置换群)
POJ 1026 Cipher (置换群)
2022-08-10 10:32:00 【51CTO】
Description
Bob and Alice started to use a brand-new encoding scheme. Surprisingly it is not a Public Key Cryptosystem, but their encoding and decoding is based on secret keys. They chose the secret key at their last meeting in Philadelphia on February 16th, 1996. They chose as a secret key a sequence of n distinct integers, a1 ; …; an, greater than zero and less or equal to n. The encoding is based on the following principle. The message is written down below the key, so that characters in the message and numbers in the key are correspondingly aligned. Character in the message at the position i is written in the encoded message at the position ai, where ai is the corresponding number in the key. And then the encoded message is encoded in the same way. This process is repeated k times. After kth encoding they exchange their message.
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
The input file consists of several blocks. Each block has a number 0 < n <= 200 in the first line. The next line contains a sequence of n numbers pairwise distinct and each greater than zero and less or equal than n. Next lines contain integer number k and one message of ascii characters separated by one space. The lines are ended with eol, this eol does not belong to the message. The block ends with the separate line with the number 0. After the last block there is in separate line the number 0.
Output
Output is divided into blocks corresponding to the input blocks. Each block contains the encoded input messages in the same order as in input file. Each encoded message in the output file has the lenght n. After each block there is one empty line.
Sample Input
Sample Output
题意
给出一个 n 个数的置换,按照置换的规则将一个字符串置换 k 次,如果字符串长度不足 n ,则在末尾补空格,求置换 k 次之后的字符串是什么。
思路
本来打算模拟出一个置换的前 100000 种情况,然后把所有的结果存储在一个数组中。
只是这道题目只给了 10M 的内存限制,提交了好几次都是内存超限,再小一点又是运行错误了。
最后改成 【置换 + 轮换 + 模】 的方法之后就可以过了。
把给出的 key 写成置换的形式,然后对其分解求出每部分的轮换以及轮换的长度,因为在变换过程中每一个轮换中的元素所占有的位置不会改变,所以只是这些局部的数字会循环变化,循环的长度也就是轮换的长度。
AC 代码
边栏推荐
猜你喜欢

Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!

2023版揽胜运动曝光,安全、舒适一个不落

bus event bus use

【C语言】浮点数四舍五入

ESP8266 教程1 — ESP8266硬件平台介绍

FastReport.Net 2022.2.17 Crack

SQL中的字符串截取函数

Swin Transformer作者曹越加入智源,开展视觉基础模型研究

对话陈赐靓:哪吒要让高端产品大众化

让软件飞——“X+”技术揭秘
随机推荐
Text selection rounded style border-radius
ZZULIOJ 1124: 两个有序数组合并
自动化测试及Selenium
PTA 7-2 方阵对角线元素求和及计数 题解
Dialogue with Chen Ciliang: Nezha wants to popularize high-end products
How can an organization judge the success of data governance?
数据库事务
chart.js horizontal column chart plugin
OneFlow源码解析:算子指令在虚拟机中的执行
[C language] Header file #include
, conio is Console Input/Output (console input and output) 技能大赛训练题:组策略一
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
C语言题解:倒置字符串
ESP8266 教程2 — 烧录AT固件
YTU 2894: G--我要去内蒙古大草原
「时序数据库」使用cassandra进行时间序列数据扫描
bus event bus use
OneFlow source code parsing: operator instructions executed in a virtual machine
database constraints
C#List的使用以及Linq的使用