当前位置:网站首页>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 代码
边栏推荐
- 【C语言】头文件#include <conio.h>,conio是Console Input/Output(控制台输入输出)
- 交换 生成树 知识总结
- ZZULIOJ 1124: 两个有序数组合并
- HCIP ---- VLAN
- what is bsp in rtems
- 网络安全笔记6——数字证书与公钥基础设施
- Flutter实战-请求封装(五)之Isolate线程改造
- mysql5.7 installation and deployment - yum installation
- STM32 encapsulation ESP8266 a key configuration function: implementations of AP mode and the STA mode switch, server and the client to create
- ESP8266 教程1 — ESP8266硬件平台介绍
猜你喜欢

runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function

OneFlow源码解析:算子指令在虚拟机中的执行

String interception function in SQL

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

「业务架构」介绍BPMN第二部分-泳道

金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案

《MySQL高级篇》六、索引的创建与设计原则

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

"Time Series Database" uses cassandra to scan time series data

Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan
随机推荐
商城限时秒杀功能系统
MySQL 执行查询流程
leetcode:334. 递增的三元子序列
【Azure云】服务端点和私有链接有什么区别?观点(1)
owl.carousel海报卡片Slider轮播切换
面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
态势丨黑客侵扰加剧,靶场为网络安全架设“防御盾”
LeetCode Algorithm 1721. 交换链表中的节点
【C语言】头文件#include <conio.h>,conio是Console Input/Output(控制台输入输出)
让软件飞——“X+”技术揭秘
String interception function in SQL
database transaction
内存问题难定位,那是因为你没用ASAN
WebView2 通过 PuppeteerSharp 实现爬取 王者 壁纸 (案例版)
「数据战略」结果驱动的企业数据策略:组织和治理
【Redis】Redis入门教程(介绍 下载安装 Jedis 图形化界面)
技能大赛训练题:组策略一
MongoDB database notes
bus event bus use
Pycharm终端出现PS问题、conda或activate不是内部命令问题..