标签:des style http color io os java ar strong
BFS.....
2345 3 7 8 9 100 1 0
Case 1: 2345 Case 2: -1
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <set> #include <string> using namespace std; string num[10]={"0","1","2","3","4","5","6","7","8","9"}; int n,m; bool ex[10]; struct SU { int yu; string num; }; bool vis[200000]; int main() { int cas=1; while(scanf("%d",&n)!=EOF&&n) { scanf("%d",&m); for(int i=0;i<10;i++) ex[i]=true; for(int i=0;i<m;i++) { int a; scanf("%d",&a); ex[a]=false; } printf("Case %d: ",cas++); queue<SU> q; memset(vis,0,sizeof(vis)); for(int i=1;i<=9;i++) { if(ex[i]==true) { q.push((SU){i%n,num[i]}); vis[i*10]=true; } } bool flag=false; while(!q.empty()) { SU u=q.front(); q.pop(); if(u.yu==0) { cout<<u.num<<endl; flag=true; break; } for(int i=0;i<10;i++) { if(ex[i]==false) continue; int newyu=(u.yu*10+i)%n; if(vis[newyu*10+i]==true) continue; vis[newyu*10+i]=true; q.push((SU){newyu,u.num+num[i]}); } } if(flag==false) puts("-1"); } return 0; }
HDOJ 4474 Yet Another Multiple Problem
标签:des style http color io os java ar strong
原文地址:http://blog.csdn.net/ck_boss/article/details/39324865