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

ft

Posted by harvard at 2005-05-10 23:06:12 on Problem 1026
In Reply To:求模了怎么还TLE啊……救救我!…… Posted by:00448028 at 2005-05-10 23:03:45
> 还有哪里会导致超时呢??焦头烂额了……
> 
> #include <iostream>
> #include <string>
> using namespace std;
> 
> void main()
> {
> 	unsigned long n, k, i, j;
> 	while( cin >> n && n != 0 )
> 	{
> 		unsigned long *a = new unsigned long[n];
> 		for( i = 0; i < n; i ++ )
> 			cin >> a[i];
> 		while( cin >> k && k != 0 )
> 		{
> 			cin.ignore();
> 			string str(n, 32);
> 			for( i = 0; i < n; i ++ )
> 			{
> 				char temp = cin.get();
> 				if( temp == '\n' )
> 					break;
> 				else str[i] = temp;
> 			}
> 			string str1(str);
> 			for( j = 1; j <= k; j ++ )
> 			{
> 				string temp(n, 32);
> 				for( i = 0; i < n; i ++ )
> 					temp[a[i] - 1] = str1[i];
> 				str1.assign(temp);
> 				if( str1 == str )              //已经求模了
> 				{
> 					k %= j;
> 					j = 0;
> 				}
> 			}
> 			cout << str1 << endl;
> 		}
> 		delete[]a;
> 		cout << endl;
> 	}
> }

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