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 ...
随机推荐
- C#综合笔记
AspNetPager分页控件 UrlPaging="true" 利用get方式page?=1进行分页. UrlPaging="false"利用post方式进行 ...
- js之oop <三>属性标签
读取属性标签 获取对象属性标签,用 Object.getOwnPropertyDescriptor方法.getOwnPropertyDescriptor(); 参数:属性所在对象(object),属性 ...
- How to change owner of PostgreSql database?
ALTER DATABASE name OWNER TO new_owner;
- IP和端口的相关检测
1.查看自己电脑的ip,使用ipconfig命令 2.检测某个ip是否可以连通,直接使用ping命令 3.windows下查看本机都有哪些端口开放,使用netstat -anp tcp 命令 4.查看 ...
- UIDatePicker的用法
目录[-] 1.Locale 2.Calendar 3.timeZone 4.date 5.minimumDate 6.maximumDate 7.countDownDuration 8.minute ...
- node.js基础 1之 URL网址解析的好帮手
URL和URI的区别: URL是统一资源定位符 URI是统一资源标识符 URL是URI的子集(URL一定是URI,但URI不一定是URL) node中的URL中的url.parse protocol: ...
- [kylin] 部署kylin服务
一.工具准备 zookeeper3.4.6 (hadoop.hbase 管理工具) Hadoop. Hbase1.1.4 Kylin1.5.0-HBase1.1.3 Jdk1.7.80 Hive 二. ...
- 【CSS3】标签使用说明
转换(transform):改变元素的形状.大小和位置. transform:rotate(20deg):顺时针旋转20° rotate()用来2D旋转改变角度.支持负数,表示逆时针. transfo ...
- android 中theme样式的解释
android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式 android:theme="@androi ...
- Linux字符设备
一.linux系统将设备分为3类:字符设备.块设备.网络设备. 字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面向流的设备,常见的 ...