标签:style blog color io os ar for 数据 sp
题意 :lucky cat里有翻译。英文也比较好懂。
很容易发现有周期然后就拍就好了
注意每组数据后边都有空行 包括最后一组。一开始以为最后一组没有空行。唉。。
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} int t[210];//周期 int N,pos[210],tmp[210]; int k,T,res; char input[210];int ans[210]; void dfs(int cur,int depth) { if (cur == res) {T = depth; return ;} dfs(pos[cur],depth + 1); } void calcu() { for (int i = 1; i <= N; i++) { res = i; dfs(pos[i],1); t[i] = T ; } } int main() { //freopen("sample.txt","r",stdin); bool first = false; while (scanf("%d",&N)!=EOF) { if (N == 0) break; for (int i = 1; i <= N; i++) scanf("%d",&pos[i]); calcu(); //for (int i = 1; i <= N; i++) printf("%d ",t[i]);putchar(‘\n‘); while (scanf("%d",&k) != EOF) { if (k == 0) break; getchar(); gets(input+1); int len = strlen(input + 1); for (int i = len + 1; i <= N; i++) input[i] = ‘ ‘; input[N + 1] = ‘\0‘; //for (int i = 1; i <= N; i++) printf("%d ",tmp[i]);puts(""); char output[210]; for (int i = 1; i <= N; i++) tmp[i] = i; for (int i = 1; i <= N; i++) { int tp = k % t[i]; for (int j = 0; j < tp; j++) tmp[i]=pos[tmp[i]]; } for (int i = 1; i <= N;i++) output[tmp[i]] = input[i]; for (int i = 1; i <= N;i++) printf("%c",output[i]); putchar(‘\n‘); } putchar(‘\n‘); } return 0; }
标签:style blog color io os ar for 数据 sp
原文地址:http://www.cnblogs.com/Commence/p/3996376.html