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 ...
随机推荐
- HTTP笔记之一
1 URL 统一资源定位符(URL)是资源标识符最常见的格式.大部分的URL都遵循一种标准格式,这种格式包含三个部分. URL的第一部分:方案(scheme),说明了访问资源所使用的协议类型.通常是 ...
- 程序设计入门——C语言 第4周编程练习 1 素数和(5分)
题目内容: 我们认为2是第一个素数,3是第二个素数,5是第三个素数,依次类推. 现在,给定两个整数n和m,0<n<=m<=200,你的程序要计算第n个素数到第m个素数之间所有的素数的 ...
- 协程 & 用户级(内核级)线程 & 切换开销 & 协程与异步回调的差异
今天先是看到多线程级别的内容,然后又看到协程的内容. 基本的领会是,协程是对异步回调方式的一种变换,同样是在一个线程内,协程通过主动放弃时间片交由其他协程执行来协作,故名协程. 而协程很早就有了,那时 ...
- java中的标记接口
在java 中,RandomAccess和Cloneable .Serializable一样,都是标志性接口,不需要任何实现,只是又来表明其实现类具体有某种特质的,实现了Cloneable表明可以拷贝 ...
- DELETE与TRUNCATE的区别
当执行 DELETE FROM TABLE后,会发现针对一个DELETE语句,该表中有多少行内容,数据库日志文件中,相对应的记录是就是多少条,每一条记录,对应的是行级别的删除.而且对应的LSN编号也是 ...
- 课时8—弹窗modal
首先弹窗的实现效果如下: 主要实现的代码如下: CSS: .header,.footer,.wrap-page{ position:absolute; left:; right:; backgroun ...
- cf
Financing a capital project with equity may be a signal to investors that a company's prospects are ...
- gz
不准备的话,是真的会滚粗的. leetcode 还是重新做起来叭. 那么就开始咯 8.22 leetcode 144 Binary Tree Preorder Traversal 二叉树的前序遍历 ...
- F2工作流引擎之 工作流运转模型(三)
1流程单起点单终止模型 单起点:一个流程定义必须有且唯一起点 单结束点:一个流程定义必须有且唯一结束点. 约定:提单与结束是每个流程必须有的活动,且唯一只有一个提单和结束. 2串行模型 描述:串行(S ...
- 使用urllib编写python爬虫
新版python中,urllib和urllib2合并了,统一为urllib (1)简单爬取网页 import urllib content = urllib.request.urlopen(req). ...