Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛们帮忙为什么TLE,和别人一样的方法啊?附带注释就是一遍一遍编码,找到循环后就知道循环节长度了,我看别人AC代码也这样做的啊?为什么我的TLE啊! #include <stdio.h> #include <string.h> int n; int key[210]; char code[210]; void encode() { int i; char tmp[210]; for (i=0;i<n;i++) tmp[key[i]]=code[i]; tmp[n]='\0'; strcpy(code,tmp); } int main() { long i,k,fc,con; char txt[210]; while (scanf("%ld",&n),n) { for (i=0;i<n;i++) { scanf("%d",&key[i]); key[i]--; } while (scanf("%ld",&k),k) { getchar(); gets(txt); for (i=strlen(txt);i<n;i++) txt[i]=' '; txt[n]='\0'; strcpy(code,txt); fc=0; con=1; for (i=0;i<k;i++) { encode(); if (con && strcmp(code,txt)==0) { if (k%(i+1)<k-i) { k%=i+1; fc=1; break; } else con=0; } } if (fc) { strcpy(code,txt); for (i=0;i<k;i++) encode(); } puts(code); } printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator