标签:
1 #include<stdio.h> 2 #include<string> 3 #include<queue> 4 #include<string.h> 5 #include<algorithm> 6 #define mem(a) memset(a,0,sizeof(a)) 7 using namespace std; 8 const int MAXN=1e4+10; 9 int cmp(char a,char b){ 10 /*if(a<b)return 1; 11 else return 0;*/ 12 return a<b; 13 } 14 int vis[MAXN],pre[MAXN]; 15 char num[20]; 16 int nu[20]; 17 char al[MAXN]; 18 int n,m,C; 19 void print_ans(){ 20 int r=0; 21 string ans; 22 while(ans.empty()||r!=0){ 23 ans+=al[r]; 24 r=pre[r]; 25 } 26 reverse(ans.begin(),ans.end()); 27 puts(ans.c_str()); 28 } 29 void bfs(){ 30 queue<int>dl; 31 dl.push(0); 32 while(!dl.empty()){ 33 int f1,f2; 34 f1=dl.front();//** 35 dl.pop(); 36 for(int i=0;i<m;i++){ 37 if(nu[i]==0&&f1==0)continue; 38 f2=(f1*C+nu[i])%n; 39 if(vis[f2])continue; 40 pre[f2]=f1; 41 al[f2]=num[i]; 42 if(f2==0){ 43 //printf("%d %d\n",f1,f1*C+nu[i]); 44 print_ans(); 45 return; 46 } 47 vis[f2]=1; 48 dl.push(f2); 49 } 50 } 51 puts("give me the bomb please"); 52 } 53 int main(){ 54 int T; 55 scanf("%d",&T); 56 while(T--){ 57 mem(vis);mem(pre);mem(al); 58 char x[5]; 59 scanf("%d%d%d",&n,&C,&m); 60 for(int i=0;i<m;i++){ 61 scanf("%s",x); 62 num[i]=x[0]; 63 //printf("%c ",num[i]); 64 } 65 sort(num,num+m); 66 int o=0; 67 for(int i=0;i<m;i++){ 68 if(num[i]>=‘A‘&&num[i]<=‘Z‘)nu[i]=10+num[i]-‘A‘; 69 else nu[i]=num[i]-‘0‘; 70 if(num[i]==‘0‘)o=1; 71 //printf("%c %d ",num[i],nu[i]); 72 } 73 if(n!=0)bfs(); 74 else if(o)puts("0"); 75 else puts("give me the bomb please"); 76 } 77 return 0; 78 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4865554.html