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 everease at 2012-01-04 00:13:59 on Problem 1426
#include <stdio.h>
#define MAXN 205
#define MAXSIZE 1000

typedef struct{
     int rem;
     int fa;
     int add;
}Node;

int main(){
     int n,i,j,head,tail,tmp;
     int flag[MAXN];
     Node node[MAXSIZE];
     int ans[MAXN];

     for(scanf("%d",&n);n!=0;scanf("%d",&n)){
	
	  if(n==1){
	       printf("%d\n",1);
	       continue;
	  }

	  for(i=0;i<n;i++)
	       flag[i]=0;

	  flag[1]=1;

	  head=0;
	  node[head].rem=1;
	  node[head].fa=-1;
	  node[head].add=1;

	  tail=1;

	  for(;;head++){
	      
	       tmp=(node[head].rem)*10;
	       tmp%=n;
	       if(flag[tmp]==0){
		  
		    flag[tmp]=1;
		    node[tail].rem=tmp;
		    node[tail].fa=head;
		    node[tail].add=0;
		    if(tmp==0)
			 break;
		    tail++;
	       }

	       tmp++;
	       if(tmp==n)
		    tmp=0;
	       if(flag[tmp]==0){
		    flag[tmp]=1;
		     node[tail].rem=tmp;
		    node[tail].fa=head;
		    node[tail].add=1;
		    if(tmp==0)
			 break;
		    tail++;
	       }
	  }

	  
	  for(i=tail,j=0;node[i].fa!=-1;i=node[i].fa,j++){
	       ans[j]=node[i].add;
	  }

	  printf("1");
	  for(j--;j>=0;j--){
	       printf("%d",ans[j]);
	  }
	  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