标签:代码 tchar SM algorithm 思路 put size style nlog
题解:
似乎大家都是求置换群的取模啊
给一个不同的思路
快速幂!!!
似乎速度比取模快多了(nlogk)
代码:
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; const int N=205; int n,a[N],b[N],p[N],k; char s[N]; void ksm(int x) { if (!x) { for (int i=1;i<=n;i++)a[i]=i; return; } ksm(x/2); for (int i=1;i<=n;i++)b[i]=a[a[i]]; for (int i=1;i<=n;i++)a[i]=b[i]; for (int i=1;i<=n;i++) if (x%2==1)b[i]=p[a[i]]; for (int i=1;i<=n;i++)a[i]=b[i]; return; } int main() { while (scanf("%d",&n),n) { for (int i=1;i<=n;i++)scanf("%d",&p[i]); while (scanf("%d",&k),k) { getchar(); ksm(k); memset(s,0,sizeof s); gets(s+1); for (int i=strlen(s+1)+1;i<=n;i++)s[i]=‘ ‘; for (int i=1;i<=n;i++)b[a[i]]=i; for (int i=1;i<=n;i++)putchar(s[b[i]]); puts(""); } puts(""); } return 0; }
标签:代码 tchar SM algorithm 思路 put size style nlog
原文地址:https://www.cnblogs.com/xuanyiming/p/8977132.html