poj1026 Cipher ——置换群
link:http://poj.org/problem?id=1026
其实这道题目和poj2369这道题目一样。
都是基础的置换群题目。把那道题目理解了,这道题就没问题了。
不过我的方法貌似比较挫,或者处理方法效率不高,比较慢……
就是对每个数字求出循环节,用rec[]保存,然后用k%rec[]得到余数,
再模拟这个余数次就得到了目标位置。
/*
ID: zypz4571
LANG: C++
TASK: decode.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
];
], a[], b[], c[];
];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
int n, k;
while (~scanf("%d", &n)) {
if (!n) break;
; i < n; ++i) scanf();
memset(rec, , sizeof(rec));
memset(flag, false, sizeof(flag));
vector<int> tmp;
; i <= n; ++i) {
tmp.clear();
if (!flag[i]) {
, pos = i;
while (!flag[a[pos]]) {
sum++; flag[a[pos]] = true; tmp.push_back(a[pos]); pos = a[pos];
}
; j < tmp.size(); ++j) rec[tmp[j]] = sum;
}
}
while (~scanf("%d", &k)) {
if (!k) break;
getchar();
gets(str);
int len = strlen(str);
if (len < n) {
for (int i = strlen(str); i < n; ++i) str[i]=' ';
str[n]='\0';
}
; i <= n; ++i) {
, pos = i;
memset(flag, false, sizeof(flag));
while (!flag[a[pos]]) {
if (sum >= cnt) break;
sum++; flag[a[pos]] = true; pos = a[pos];
}
b[i] = pos;
}
; i <= n; ++i) c[b[i]] = str[i-];
; i <= n; ++i) printf("%c", c[i]);
printf("\n");
}
printf("\n");
}
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
每个block后面加一个空行!输出格式搞清楚
嗨,中村。
poj1026 Cipher ——置换群的更多相关文章
- Cipher(置换群)
Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20821 Accepted: 5708 Descripti ...
- POJ1026 Cipher(置换的幂运算)
链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- poj1026 Cipher
题目意思可概括为给定集合S = {1,..,n}的一个双射关系f, 求经过k次复合之后元素i对应的元素fk(i) (i∈S). 由于函数是双射,一个原像对应唯一一个像,同样一个像有唯一一个原像,考虑整 ...
- POJ 1026 Cipher(置换群)
题目链接 题意 :由n个数字组成的密钥,每个数字都不相同,都在1-n之间,有一份长度小于等于n的信息,要求将信息放到密钥下边,一一对应,信息不足n的时候补空格,然后将位置重新排列,将此过程重复k次,求 ...
- JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher
加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...
- BZOJ 1031: [JSOI2007]字符加密Cipher 后缀数组
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6014 Solved: 2503[Submit ...
- freeCodeCamp:Caesars Cipher
让上帝的归上帝,凯撒的归凯撒. 下面我们来介绍风靡全球的凯撒密码Caesar cipher,又叫移位密码. 移位密码也就是密码中的字母会按照指定的数量来做移位. 一个常见的案例就是ROT13密码,字母 ...
- ural Cipher Message
Cipher Message Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- 紫书例题-Ancient Cipher
Ancient Roman empire had a strong government system with various departments, including a secret ser ...
随机推荐
- InfoObject共享
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 《BI那点儿事—数据的艺术》理解维度数据仓库——事实表、维度表、聚合表
事实表 在多维数据仓库中,保存度量值的详细值或事实的表称为“事实表”.一个按照州.产品和月份划分的销售量和销售额存储的事实表有5个列,概念上与下面的示例类似. Sate Product Mouth U ...
- 19 Using Optimizer Hints
19.1 Overview of Optimizer Hints A hint is an instruction to the optimizer. In a test or development ...
- angular 三目运算符 需要换色或style
解决方法:直接简单粗暴写两个.有点挫,但实现需求了. <font style="color:red" ng-show="boxlist.lineTitle.leng ...
- python窗体——pyqt初体验
连续两周留作业要写ftp的作业,从第一周就想实现一个窗体版本的,但是时间实在太短,qt零基础选手表示压力很大,幸好又延长了一周时间,所以也就有了今天这篇文章...只是为了介绍一些速成的方法,还有初学者 ...
- 51nod 1051 最大子矩阵和(dp)
题目链接:51nod 1051 最大子矩阵和 实质是把最大子段和扩展到二维.读题注意m,n... #include<cstdio> #include<cstring> #inc ...
- [转]Jenkins Xcode打包ipa
本地打包. 如果Mac 上没有安装brew.先安装:ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/ins ...
- 使用scp将文件/目录拷贝到另一台Linux主机上
如何将一台Linux主机上的文件或目录拷贝到另一台Linux主机上,scp命令可以实现该需求 前提条件:两台Linux主机处于同一网段,可以互相ping通 操作如下: 文件拷贝 ①将本地文件拷贝到远端 ...
- Linux有用命令
1.nohup命令 使用方法:nohup ./run.sh 作用:忽略所有挂断(SIGHUP)信号,不挂断地运行命令
- 使用squid配置透明代理并对上网行为进行控制
使用Squid配置透明代理 环境:CentOS 6.4 + squid-3.1.10-20.el6_5.3.x86_64 1.检查squid是否默认安装,没有安装先安装 rpm -qa squid 假 ...