UVA 725 Division (hash+ enumeration)

Source: Internet
Author: User

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)

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.