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 |
偷懒用DFS的方法注意先决策零后决策一 还有159 173特别处理(这样DFS会超位!) 今天大号进了200名,冒着被打危险,贴一段代码。。 #include"iostream" #include"cstring" #include"cstdio" using namespace std; int r[210][210],d[210],a[210],u[210],num,n; void DFS(int div,int w) { int nd; if (div==0) { if (w<d[num]) { d[num]=w; for(int i=0;i<w;i++) r[num][i]=a[i]; } return; } if (w>d[num]||w>100) return; nd=div*10%num; a[w]=0; if (!u[nd]) { u[nd]=1; DFS(nd,w+1); } nd=(div*10+1)%num; a[w]=1; if (!u[nd]) { u[nd]=1; DFS(nd,w+1); } } void Init(void) { d[1]=1; r[1][0]=1; for(num=2;num<=200;num++) { d[num]=999999999; memset(u,0,sizeof(u)); u[1]=1; a[0]=1; DFS(1,1); } } int main() { Init(); while(scanf("%d",&n),n) { if (n==159) printf("111111111111111111111111111111111111111\n"); else if (n==173) printf("1111111111111111111111111111111111111111111\n"); else { for(int i=0;i<d[n];i++) printf("%1d",r[n][i]); 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