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 ...
随机推荐
- CUBRID学习笔记 48查询优化
cubrid的中sql查询语法 查询优化 c#,net,cubrid,教程,学习,笔记欢迎转载 ,转载时请保留作者信息.本文版权归本人所有,如有任何问题,请与我联系wang2650@sohu.com ...
- KVC与KVO
KVC:键值编码(Key-Value-Coding),是一个非正式的Protocol,提供一种机制间接访问对象的属性,是路径访问的规范: KVO:键值观察 (Key-Value-Observe),是基 ...
- 【BZOJ】1407 NOI 2002 荒岛野人Savage
拓展欧几里得入门题 两个野人若要走到同一个洞穴,设他们走了x步,则p[i]*x+c[i]≡p[j]*x+c[j](mod ans),ans即答案: 移项得到(p[i]-p[j])*X+ansY=c[j ...
- hdu 3887 Counting Offspring dfs序+树状数组
Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Python编程练习题
1 求可用被17整除的所有三位数 for num in range(99,1000): if num % 17 == 0: print num ps:下面的写法和上面的写法性能的差距,上面好吧? fo ...
- 怎样去除ul li a标签文字下的下划线
这个主要是text-decoration属性,颜色的话就是普通的了 <style> ul li a{ text-decoration:none; } ul li a { color: ...
- switch多分支语句简析
在编程中一个常见问题就是检测一个变量是否符合某个条件,switch以一个简单明了的方式来实现类似于"多选一"的选择,语法格式如下: /*switch首先计算表达式的值,如果表达式的 ...
- 数据库 基础篇4(mysql语法---表)
5 表管理 选择数据库 5.1 查看所有表 mysql> show tables; +-----------------+ | Tables_in_day15 | +------------ ...
- Linux 系统启动过程
linux启动时我们会看到许多启动信息. Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段: 内核的引导. 运行init. 系统初始化. 建立终端 . 用户登录系统. 内核引 ...
- c语言完成分块查找
首先要把一系列数组均匀分成若干块(最后一个可以不均匀) 每块中元素任意排列,即块中数字无序,但是整个块之间要有序.因此也存在局限性. #include<stdio.h> //分块查找法 v ...