zoukankan      html  css  js  c++  java
  • UVa 725 Division

    题意:求满足形如abcde/efghi=n的五位数

    从i=1234(因为可以有前导0)到98765枚举,(i*n)/i=n,再判断各个位数是否相同即可

     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("
    ");
    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
    ",m,i,n);
    50                 ans++;
    51             }                        
    52         }
    53         
    54         if(flag==0&&ans==0) printf("There are no solutions for %d.
    ",n);
    55     }
    56     return 0;
    57 }
    View Code

    这道题目从tle,tle,tle,到ce,到wa,= =555555555555

    go---go---go

  • 相关阅读:
    FirstApp,iphone开发学习总结
    FirstApp,iphone开发学习总结7,相机
    FirstApp,iphone开发学习总结6,Navigation的使用
    FirstApp,iphone开发学习总结1,UIview添加UIimage
    oracle 12cR2 RAC deconfig CRS过程记录
    Activex word
    图片灰度化。
    vb word
    加密
    页面内打开word 组件。
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4349338.html
Copyright © 2011-2022 走看看