Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求模几步就搞掂了,为何TLE?入来看看如何?

Posted by Algor at 2010-03-03 20:33:50 on Problem 1026
//cipher
//Time Limit Exceeded
//20100125
#include<iostream>
using namespace std;
int arr[205],block;
char c[205],coded[205],msg[205];
bool isSame()
{
	for(int i=0;i<block;i++){
		if(msg[i]!=coded[i])
			return false;
	}
	return true;
}
int main()
{
	int k,i,j,cnt;
	while(scanf("%d",&block)&&block){
		for(i=0;i<block;i++)
			scanf("%d",arr+i);
		while(scanf("%d",&k)&&k)
		{
			scanf(" ");
			gets(c);
			int len=strlen(c);
			for(i=0;i<block;i++)
				coded[i]=' ';
			for(i=len;i<block;i++)
				c[i]=' ';
			strcpy(msg,c);
			cnt=0;
			if(k>0){
				for(j=0;j<k;j++)
				{
					cnt++;
					for(i=0;i<block;i++)
						coded[arr[i]-1]=c[i];
					if(isSame()){
						k%=cnt;
						break;
					}
					else{
						for(i=0;i<block;i++)
							c[i]=coded[i];
					}
				}
			}
			if(cnt)
				strcpy(c,msg);
			//cout<<k<<" "<<cnt<<endl;
			for(j=0;j<k;j++)
			{
				for(i=0;i<block;i++)
					coded[arr[i]-1]=c[i];
				for(i=0;i<block;i++)
					c[i]=coded[i];
			}
			for(i=0;i<block;i++)
				printf("%c",coded[i]);
			printf("\n");
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator