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

哪位仁兄帮忙看哈到底哪里有问题,挂得不行了

Posted by baoer at 2008-05-04 23:55:26 on Problem 3590
算法:
题目要求就是求出置换群最大周期,可以转化成为这样的问题:
求X个自然数和为N,使其积最大.然后得到的X个数为一个内循环数,
再按字典序生成目标置换.

代码:
#include <stdio.h>
#include <math.h>

int main(void)
{
     int t,n,i,j,k,x,m,sign,tt;
	 double sum,max,y;
	 scanf("%d",&t);
	 while(t--)
	 {
	      scanf("%d",&n);
		  max=n;
		  x=n;
		  tt=0;
		  for(i=1;i<=n;i++)
		  {
		       if(n%i==0)
			   {
				   sign=0;
			       sum=pow(i,n/i);
			   }
			   else if(n%i==1)
			   {
				   sign=0;
				   sum=pow(i,n/i-1)*(i+n%i);
			   }
			   else
			   {
			       sum=pow(i,n/i)*(n%i);
				   y=pow(i,n/i-1)*(i+n%i);
				   if(sum>=y)
					   sign=1;
				   else
				   {
				       sign=0;
					   sum=y;
				   }
			   }
			   if(sum>max)
			   {
				   max=sum;
			       x=i;
				   tt=sign;
			   }
		  }
		  printf("%.0lf ",max);
		  if(tt==1)
		  {
		       for(j=1;j<x-1;j++)
			   printf("%d ",j+1);
			   printf("1 ");
			   i=n%x+1;
		  }
		  else
		  i=1;
		  for(;i<n-x;i+=x)
		  {
		       for(j=i;j<i+x-1;j++)
			   printf("%d ",j+1);
			   printf("%d ",i);
		  }
		  for(j=i;j<n;j++)
		  printf("%d ",j+1);
		  printf("%d",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