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

为啥总是Re啊,上百练试下都AC了,这边还是Re……

Posted by 445229605 at 2012-11-04 18:05:07 on Problem 1026
#include <iostream>
#include <string>
#include <memory.h>
using namespace std;
int a[201][201],b[201],c[201],n;
string s;
void f()//迭代n次
{
	for(int i=2;i<=n+1;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[i][j]=a[1][a[i-1][j]];
		}
	}
}
void g()//算出每个数循环的长度
{
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=n+1;j++)
		{
			if(a[j][i]==a[1][i]){b[i]=j-1;break;}
		}
	}
}

int main()
{
	int times;
	char tempc;
	int temp;
	while(cin>>n&&n!=0)
	{
		memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++)
		{
			cin>>a[1][i];
		}
		while(cin>>times&&times!=0)
		{
			if(n==1){cin>>s;cout<<s<<endl;continue;}
			f();g();
			memset(c,0,sizeof(int)*201);
			cin.get();
			getline(cin,s);
			int len=s.length();
			while(len<n)
			{s=s+" ";len++;}
			for(int j=1;j<=n;j++)
			{
				int z=times%b[j];
				if(z==0)
				{c[j]=a[b[j]][j];}
				else
				{
					c[j]=a[z][j];
				}
			}
			for(int p=0;p<=n-2;p++)
			{
				for(int q=p+1;q<=n-1;q++)
				{
					if(c[p+1]>c[q+1])
					{
						temp=c[p+1];c[p+1]=c[q+1];c[q+1]=temp;
						tempc=s[p];s[p]=s[q];s[q]=tempc;
					}
				}
			}
			cout<<s<<endl;
		}
		cout<<endl;
	}
	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