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

急急急急。。。高手指点:为什么我这个程序总是Runtime Error?

Posted by d20061988 at 2008-07-30 14:32:18 on Problem 1833
#include<iostream>
using namespace std;
void mul(int n,int *p)
{
	int sum,i,j;
	p[0]=1;
	for(j=1;j<=n;j++)
	{
	sum=1;
	for(i=1;i<=j;i++)
		sum*=i;
	p[j]=sum;
	}
}
int permrank(int n,int *pi,int *f)
{
	int r=0;
	int *rho,j,i;
	rho=new int[n];
	for(j=0;j<n;j++) rho[j]=pi[j];
	for(j=0;j<n;j++){
		r+=(rho[j]-1)*f[n-j-1];
		if(j+1<n)
		for(i=j+1;i<n;i++) if(rho[i]>rho[j]) rho[i]--;
	}
	delete rho;
	return r;
}
void permunrank(int n,int r,int *pi,int *f)
{
	pi[n-1]=1;
	int j,d,i;
	for(j=0;j<n-1;j++)
	{
		d=(r%f[j+2])/f[j+1];
		r-=d*f[j+1];
		pi[n-j-2]=d+1;
		for(i=n-j-1;i<n;i++) if(pi[i]>d) pi[i]++;
	}
}
int main()
{
	int n,*pi,i,r,m,j,*p;
	pi=new int[2048];
	p= new int[2049];
	cin>>m;
	for(j=0;j<m;j++){
		cin>>n>>r;
  for(i=0;i<n;i++)
	  cin>>pi[i];
  mul(n,p);
  permunrank(n,permrank(n,pi,p)+r,pi,p);
 for(i=0;i<n;i++)
	 cout<<pi[i]<<" ";
 cout<<endl;
	}
	delete pi;
	delete p;
 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