POJ 1027 Cipher(置换)
来源:互联网 发布:淘宝上哪家小叶紫檀好 编辑:程序博客网 时间:2024/05/24 07:18
题意:第i个移动到a[i]。问k次之后的字符串。
思路:置换求循环节。
#include <algorithm>#include <iostream>#include <sstream>#include <cstring>#include <cstdio>#include <vector>#include <string>#include <queue>#include <stack>#include <cmath>#include <set>#include <map>using namespace std;typedef long long LL;#define mem(a, n) memset(a, n, sizeof(a))#define ALL(v) v.begin(), v.end()#define si(a) scanf("%d", &a)#define sii(a, b) scanf("%d%d", &a, &b)#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)#define pb push_back#define eps 1e-8const int inf = 0x3f3f3f3f, N = 2e2 + 5, MOD = 1e9 + 7;int T, cas = 0;int n, k;char s[N];bool vis[N];struct node {int num, len;} a[N];int main(){#ifdef LOCAL freopen("/Users/apple/input.txt", "r", stdin);//freopen("/Users/apple/out.txt", "w", stdout);#endif while(si(n) != EOF) { for(int i = 1; i <= n; i ++) si(a[i].num); mem(vis, false); for(int i = 1; i <= n; i ++) { int cnt = 0, idx = i; while(!vis[idx]) { vis[idx] = 1; cnt ++; idx = a[idx].num; } idx = i; for(int j = 0; j < cnt; j ++) { a[idx].len = cnt; idx = a[idx].num; } } while(si(k), k) { gets(s); char ans[N]; int sz = strlen(s); for(int i = sz; i <= n; i ++) s[i] = ' '; s[n+1] = '\0'; for(int i = 1; i <= n; i ++) { int cnt = k % a[i].len, idx = i; for(int i = 0; i < cnt; i ++) idx = a[idx].num; ans[idx] = s[i]; } ans[n+1] = '\0'; puts(ans + 1); } puts("");} return 0;}
0 0
- POJ 1027 Cipher(置换)
- POJ 1026 Cipher 置换
- poj 1026 Cipher(置换)
- POJ 1026 Cipher 置换群
- poj-1026-Cipher-置换群
- POJ 1026 Cipher 置换群
- POJ 1026 Cipher(置换)
- POJ 1026 Cipher (置换群)
- poj 1026 Cipher (置换群)
- poj 1026 Cipher (置换群)
- POJ 1026-Cipher(置换群)
- POJ 1026 - Cipher【置换群】
- POJ 1026 Cipher 置换群
- POJ 1026 Cipher 置换群
- poj 1026 Cipher(置换)
- poj 1026 Cipher(置换群)
- POJ 1026 Cipher(置换群)
- POJ 1026 Cipher(置换)
- MySQL常用操作(笔记比较乱学完整理)
- springmvc的基础环境搭建
- Linux shell 的字符串截取
- 计算几何-多边形的重心
- Linux 命令 返回值
- POJ 1027 Cipher(置换)
- 面向对象
- 深入理解Java注解(Annotation)--自定义注解
- ruby从1.9.2-->1.9.3 i18n配置变更
- Runtime.getRuntime().exec方法
- 泛型
- SlidingMenu使用Demo
- 基于KNN的相关内容推荐
- Android 腾讯优图开发问题总结