UVa 725 Division
题意:求满足形如abcde/efghi=n的五位数
从i=1234(因为可以有前导0)到98765枚举,(i*n)/i=n,再判断各个位数是否相同即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<queue> 9 #include<set> 10 #include<algorithm> 11 using namespace std; 12 13 typedef long long LL; 14 int hash[1005]; 15 int a[1005],b[1005]; 16 17 18 int main(){ 19 int n,i,j,k,p,q,t,ans; 20 int ok=1; 21 while(scanf("%d",&n)!=EOF&&n){ 22 int flag=0,ans=0; 23 if(ok) ok=0; 24 else printf("\n"); 25 for(i=1234;i<=98765;i++){ 26 memset(hash,0,sizeof(hash)); 27 if(i*n>100000) break; 28 29 a[1]=i/10000;hash[a[1]]++; 30 a[2]=i/1000%10;hash[a[2]]++; 31 a[3]=i/100%10;hash[a[3]]++; 32 a[4]=i/10%10;hash[a[4]]++; 33 a[5]=i%10;hash[a[5]]++; 34 35 int m=i*n; 36 37 b[1]=m/10000;hash[b[1]]++; 38 b[2]=m/1000%10;hash[b[2]]++; 39 b[3]=m/100%10;hash[b[3]]++; 40 b[4]=m/10%10;hash[b[4]]++; 41 b[5]=m%10;hash[b[5]]++; 42 43 for(t=0;t<=9;t++){ 44 if(hash[t]!=1) break; 45 } 46 47 if(t<=9) flag=0; 48 else{ 49 printf("%05d / %05d = %d\n",m,i,n); 50 ans++; 51 } 52 } 53 54 if(flag==0&&ans==0) printf("There are no solutions for %d.\n",n); 55 } 56 return 0; 57 }
这道题目从tle,tle,tle,到ce,到wa,= =555555555555
go---go---go