当前位置:网站首页>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 代码
边栏推荐
- 3 injured in 'electrical accident' at Google data center
- [Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
- runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
- 「可扩展性」可扩展性最佳实践:来自eBay的经验教训
- 快速上手,征服三种不同分布式架构调用方案
- 金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案
- OneFlow source code parsing: operator instructions executed in a virtual machine
- Redis6 (1) - Introduction to NoSQL Database and Installation of Redis
- 14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
- 2022.8.9-----leetcode.1413
猜你喜欢
跨公网环境,路由策略,进行设备的访问
mysql5.7安装部署-yum安装
越折腾越好用的 3 款开源 APP
TCP/IP笔记
bus event bus use
ISO9001在讲什么?过程方法和风险思维
[Concept of Theory of Knowledge] "Progress in the Theory of Reason" University of Leuven 2022 latest 220-page doctoral dissertation
Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!
对话陈赐靓:哪吒要让高端产品大众化
chart.js horizontal column chart plugin
随机推荐
MongoDB database notes
14道高频手写JS面试题及答案,巩固你的JS基础
第3章-线性方程组(3)
MySQL executes the query process
Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan
OneFlow source code parsing: operator instructions executed in a virtual machine
技能大赛训练题:组策略一
Text selection rounded style border-radius
态势丨黑客侵扰加剧,靶场为网络安全架设“防御盾”
Flutter实战-请求封装(五)之Isolate线程改造
C语言题解:倒置字符串
PPT | 「课件」企业中高层人员安全管理培训(118页)
2022.8.7-----leetcode.636
chart.js水平柱状图插件
Dry goods!ASSANet: Making PointNet++ faster and stronger
"Data Strategy" Results-Driven Enterprise Data Strategy: Organization and Governance
面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
Regarding the missing json converter, the error message is: No converter found for return value of type
Introduction to cross-end development of Taro applet
这些年我开源的几个小项目