Main topic:
It gives you a abcde/fghij = N expression, gives you an n, and lets you find out how many of these equations you have.
Problem Solving Ideas:
The simplest enumeration, to note that we only need to enumerate out fghij on it, because Abcde=fghij*n, so, the time complexity of 10!
Down to 5! , at the end of the enumeration, we only need to determine whether 0-9 of these numbers appear and only occur once. Then for numbers over 5 digits, we
Break off directly.
The output of this problem must pay attention to that leading 0,, initially forget, WA two times, and then decisively with SETW (5) and Setfill (' 0 ') to get it done.
This statement can also be done with printf ("%d/%05d =%d\n", tt,t,n);
Code:
# include<cstdio># include<iostream># include<algorithm># include<functional># include<cstring># include<string># include<cstdlib># include<iomanip># include<numeric># include<cctype># include<cmath># include<ctime># include<queue># include<stack># include<list># include<Set># include<map>using namespacestd;Const DoublePi=4.0*atan (1.0); typedefLong Longll;typedef unsignedLong Longull;# define INF999999999intN;intnum[Ten];intCheck (intXinty) {memset (num,0,sizeof(num)); intA =x; intb =y; for(inti =0; I <5; i++) {Num[a%Ten]++; Num[b%Ten]++; A/=Ten; b/=Ten; } for(inti =0; I <Ten; i++ ) { if(num[i]!=1 ) return 0; } return 1;}intMainvoid){ intIcase =1; while(cin>>N) {if(n==0 ) Break; if(Icase >1) cout<<Endl; intFlag =0; for(intt =1234;; t++ ) { inttt = t*N; if(TT >=100000 ) Break; if(check (tt,t)) {flag=1; printf ("%d/%05d =%d\n", Tt,t,n); //printf ("%d/%d =%d\n", tt,t,n); } } if( !flag) {printf ("There is no solutions for%d.\n", N); } icase++; } return 0;}View Code
UVA 725 Division (hash+ enumeration)