Description

 

Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where 2<=N<=79. That is,

abcde / fghij =N

where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.

Input

Each line of the input file consists of a valid integer N. An input of zero is to terminate the program.

Output

Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator).

Your output should be in the following general form:

xxxxx / xxxxx =N

xxxxx / xxxxx =N

.

.

In case there are no pairs of numerals satisfying the condition, you must write ``There are no solutions for N.". Separate the output for two different values of N by a blank line.

Sample Input

61
62
0

Sample Output

There are no solutions for 61.

79546 / 01283 = 62
94736 / 01528 = 62 分析:如果将abcde与fghij都枚举出来会超时,所以只枚举fghij再用N乘以它就可以得到abcde,在判断a-j中各个数字都不同就可以了。
#include <iostream>
#include <cstdio>
using namespace std;
int used[10];
int image(int x,int y)
{
if(y>98765)
return 0;
for(int i=0;i<10;i++)
used[i]=0;
if(x<10000)
used[0]=1;
while(x)
{
used[x%10]=1;
x/=10;
}
while(y)
{
used[y%10]=1;
y/=10;
}
int sum=0;
for(int i=0;i<10;i++)
sum+=used[i];
return (sum==10); }
int main()
{
int n,t=0;
while(scanf("%d",&n)==1&&n)
{
int flag=0;
if(t++)
printf("\n");
for(int i=1234;i<100000;i++)
{
if(image(i,i*n))
{
printf("%05d / %05d = %d\n",i*n,i,n);
flag=1; }
}
if(!flag)
printf("There are no solutions for %d.\n",n);
}
}

Program A - 暴力求解的更多相关文章

  1. Program C 暴力求解

    Description   A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...

  2. Program L 暴力求解

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  3. Program B 暴力求解

    Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maxim ...

  4. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  5. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  6. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  7. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  8. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  9. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

随机推荐

  1. golang 定时器

    上网查了下相关资料,基本上都介绍的是github.com\robfig\cron这个包来执行定时任务,试了下确实可以执行.但是此包下没有删 除任务的方法,只有暂停的方法(Stop),若要停止之前的任务 ...

  2. hiho_1078_线段树区间修改

    题目 给定一组数,要求进行若干次操作,这些操作可以分为两种类型: (1) CMD 1 beg end value 将数组中下标在[beg, end] 区间内数字都变为value (2) CMD 2 b ...

  3. VIM 打造 c/c++ IDE

    1. vim 的安装 $sudo apt-get install vim vim-scripts vim-doc <br> 其中vim-scripts包含了vim的一些基本插件,包括语法高 ...

  4. Convention插件 struts零配置

    http://blog.csdn.net/spyjava/article/details/13631961系列课程使用 注解:http://www.yiibai.com/struts_2/struts ...

  5. android中的通信机制总结

      第一种:使用handler来进行通信   handler 大家可以把它想象成主线程(UI线程)的一个子线程,它可以给主线程(UI线程)发送数据从而更新主线程(UI线程)的UI与逻辑,handler ...

  6. spring boot学习

    window10的环境下 使用apache-maven-3.3.9 到https://github.com/spring-projects/spring-boot 下载源码包,解压到c:\spring ...

  7. 使用react native for android生成app

    参考文章 http://reactnative.cn/docs/getting-started.html http://www.lcode.org/react-native/ https://gith ...

  8. hdu-----(1532)Drainage Ditches(最大流问题)

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu---(4515)小Q系列故事——世界上最遥远的距离(模拟题)

    小Q系列故事——世界上最遥远的距离 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  10. Gas Station [LeetCode]

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...