| ||||||||||
| 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 | |||||||||
怎样判断K的循环点,老是超时 1015MSProblem Id:1026 User Id:flyingfish
Memory:20K Time:1015MS
Language:C++ Result:Time Limit Exceed
Source
#include<stdio.h>
#include<string.h>
int main()
{
int n,a[205],k,size,i,j,key=0;
char arry[205],brry[205],*tmp,*p,*q,pre[205];
while(scanf("%d",&n)!=EOF&&n!=0)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
while(scanf("%d",&k)!=EOF&&k!=0)
{
getchar();
gets(arry);key=0;
size=strlen(arry);
for(i=size;i<n;i++)
arry[i]=' ';
arry[i]='\0';brry[i]='\0';
for(i=0;i<=n;i++)
pre[i]=arry[i];
p=arry;q=brry;
for(i=0;i<k;i++)
{
for(j=0;j<n;j++)
q[a[j]-1]=p[j];
tmp=p;
p=q;
q=tmp;
if(strcmp(pre,p)==0)
{
key=i+1;
break;
}
}
if(key!=0)
{
printf("%d\n",key);
k=k%key;
while(k--)
{
for(i=0;i<n;i++)
q[a[i]-1]=p[i];
tmp=p;
p=q;
q=tmp;
}
}
printf("%s\n",p);
}
printf("\n");
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator