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 ...
随机推荐
- js获取url参数 兼容某些带#url
网上有大把现成的代码,不过有点小小的瑕疵 例如目前最流行的 正则法: function getArgument(_arg) { var reg = new RegExp("(^|&) ...
- poj1625Censored!(AC自动机+dp)
链接 第一次做这种题目,参考了下题解,相当于把树扯直了做DP,估计这一类题都是这个套路吧. 状态方程dp[i][next] = dp[i][next]+dp[i][j] ;dp[i][j]表示长度为i ...
- 关于 RxJava 技术介绍
Awesome-RxJava RxJava resources Blog 给 Android 开发者的 RxJava 详解 -强烈推荐 扔物线的文章 讲解非常详细 NotRxJava懒人专用指南 -这 ...
- CSS 3中边框怎么用
(1)设置边框图片的来源 图片边框默认只在四个顶点显示 none: 无背景图片; border-image-source: url('borderImage.png'); (2)边框图片的分割 将图片 ...
- 转帖-[教程] Win7精简教程(简易中度)2016年8月-0day
[教程] Win7精简教程(简易中度)2016年8月 0day 发表于 2016-8-19 16:08:41 https://www.itsk.com/thread-370260-1-1.html ...
- Java for Mac 问题
卸载jdk 1.7/1.8: sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.pluginsudo rm -fr /Library/P ...
- python之map、filter、reduce、lambda函数 转
python之map.filter.reduce.lambda函数 转 http://www.cnblogs.com/kaituorensheng/p/5300340.html 阅读目录 map ...
- python无意中发现的
http://www.zhihu.com/question/37904398?sort=created&page=2 >>> a = [[1,2],[3,4],[5,6,7] ...
- spring随手笔记1:constructor-arg
<bean id="Hello" class="com.ltf.captha.serviceImpl.HelloWorldServiceImpl"> ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...