| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
第一次贴代码
#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator