UVA 725Test Instructions: 0~9 10 number consists of two 5 digits (or four digits beginning with 0), which requires that the quotient of two numbers equals the input data n. Abcde/fghij=n. Idea: Violent enumeration, enumeration of FGHIJ cases to calculate whether the ABCDE to meet the conditions of the problem. (Note the decision of leading zeros) The enumeration method is for (int i=1234;i<=100000/n;i++) {}
#include <cstdio>#include<cstring>intnum[Ten];BOOLCheckintAintb) {memset (num,0,sizeofnum); if(b>98765)return false; if(a<10000) num[0]++; if(b<10000) num[0]++; while(a) {Num[a%Ten]++; A/=Ten; } while(b) {num[b%Ten]++; b/=Ten; } for(intI=0;i<Ten; i++) { if(num[i]>1)return false; } return true;}intMain () {intN,cnt=0; while(~SCANF ("%d", &n), n!=0) { if(cnt>0) printf ("\ n"); cnt++; intflag=0; for(intI=1234; i<=100000/n;i++) { if(Check (i,i*N)) {flag=1; printf ("%05d/%05d =%d\n", i*n,i,n); } } if(flag==0) printf ("There is no solutions for%d.\n", N); } return 0;}
UVA 10976 Test Instructions: Enter positive integer k, find all positive integers x>=y make 1/k=1/x+1/y; thought: Enumerate X, Y, consider enumeration range, because x>=y,1/x<=1/y, so y<=2k. Enumeration y in the range of k+1 to 2k to calculate the corresponding x.
#include <cstdio>intres[10010][2];intMain () {intK; while(~SCANF ("%d",&k)) {intx, y; intCnt=0; for(y=k+1; y<=2*k;y++) { if((k*y)% (y-k) = =0) {x= (k*y)/(Yk); res[cnt][0]=x;res[cnt++][1]=y; }} printf ("%d\n", CNT); for(intI=0; i<cnt;i++) {printf ("1/%d = 1/%d + 1/%d\n", k,res[i][0],res[i][1]); } } return 0;}
Enumeration: Depending on the condition of the problem, you can narrow the scope of the enumeration, enumerate a number, and calculate the other number to determine whether the condition is met.
UVA 725 UVA 10976 Simple Enumeration