UVA 725 Division (Violent enumeration)

Source: Internet
Author: User

My 56MS

1#include <cstdio>2#include <iostream>3#include <string>4#include <cstring>5#include <queue>6#include <vector>7#include <map>8#include <cmath>9 using namespacestd;Ten  One #defineMEM (a,v) memset (A,v,sizeof (a)) A //A for address, V for value -  - #defineMax (x, y) (() > (y)? ( x):(y)) the #defineMax (x, y) (() > (y)? ( x):(y)) -  - #defineDebug printf ("!\n") -  + intnum[ the]; - BOOLvisited[ the]; +  A BOOLCheckintAintb) at { -MEM (visited,false); -  -           intJ; -  -            for(j =5; j>=1; j--) in           { -                     intTMP = a%Ten; toNUM[J] =tmp; +A/=Ten; -           } the            for(j =Ten; j>=6; j--) *           { $                     intTMP = b%Ten;Panax NotoginsengNUM[J] =tmp; -B/=Ten; the           } +  A            for(j =1; j<=Ten; j + +) the           { +                     if(Visited[num[j]]) -                               return false; $VISITED[NUM[J]] =true; $           } -           return true; -  the  - }Wuyi  the intMain () - { Wu           inti,n,j,k,t=0; -            while(~SCANF ("%d", &n) &&N) About           { $                     if(t++) -printf"\ n"); -                     BOOLFind =false; -                      for(i =1234; i<=98765; i++) A                     { +                               if(i%n==0) the                               { -                                         intm = i/N; $                                         if(check (i,m)) the                                         { theFind =true; the                                          for(j =1; j<=5; j + +) theprintf"%d", Num[j]); -printf" / "); in                                          for(j =6; j<=Ten; j + +) theprintf"%d", Num[j]); theprintf"=%d\n", n); About                                         } the                               } the                     } the                     if(!find) +printf"There is no solutions for%d.\n", n); -           } the Bayi           return 0; the}

But in particular, this man wrote, there are many places worth learning

http://blog.csdn.net/mobius_strip/article/details/38735773

#include <iostream>#include<cstdlib>#include<cstdio>using namespacestd;intused[Ten];intJudgeintAintb) {    //a used array can be used to determine if there are duplicate numbers.//Place the used item at 1        if(B >98765)return 0;  for(inti =0; I <Ten; ++i) used[i]=0; if(A <10000) used[0] =1;  while(a) {Used[a%Ten] =1; A/=Ten; }     while(b) {used[b%Ten] =1; b/=Ten; }    intsum =0;  for(inti =0; I <Ten; ++i) Sum+=Used[i]; return(Sum = =Ten);}intMain () {intN, T =0;  while(~SCANF ("%d", &n) &&N) {if(T + +) printf ("\ n"); intCount =0;  for(inti =1234; I <100000; ++i) {if(Judge (I, i*N)) {printf ("%05d/%05d =%d\n", i*n,i,n); //can be filled with%05d, you don't use arrays to save numbers.Count + +; }        }        if( !count) printf ("There is no solutions for%d.\n", N); }    return 0;}

UVA 725 Division (Violent enumeration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.