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. HDU 4462 Scaring the Birds (暴力求解,二进制法)

    题意:给定一个 n*n的矩阵,在一些位置放上稻草人,每个稻草人的范围是一定,问你最少几个能覆盖整个矩阵. 析:稻草人最多才10个,所以考虑暴力,然后利用二进制法,很容易求解,并且时间很少0ms,注意有 ...

  6. 暴力求解——素环数 Prime Ring Problem ,UVa 524

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

  7. 素数环(C - 暴力求解)

    素数环(暴力)(紫书194页) Description   A ring is composed of n (even number) circles as shown in diagram. Put ...

  8. ZOJ 2856 Happy Life 暴力求解

    因为是Special Judge 的题目,只要输出正确答案即可,不唯一 暴力力求解, 只要每次改变 happiness 值为负的人的符号即可. 如果计算出当前人的 happiness 值为负,那么将其 ...

  9. POJ 3175 Finding Bovine Roots (暴力求解)

    题意:给定一串数字,问你这是一个数字开方根得到的前几位,问你是哪个数字.析:如果 x.123... 这个数字的平方是一个整数的话,那必然sqr(x.124) > ceil(sqr(x.123)) ...

随机推荐

  1. Spring Enable annotation – writing a custom Enable annotation

    原文地址:https://www.javacodegeeks.com/2015/04/spring-enable-annotation-writing-a-custom-enable-annotati ...

  2. 使用SwingBench 对Oracle RAC DB性能 压力测试

    我们可以使用swingbench这个工具对数据库性能进行压力测试,得到一些性能指标作为参考. SwingBench下载: http://www.dominicgiles.com/downloads.h ...

  3. 使用Nominatim进行openstreetmap地址搜索/解析

    Nominatim(来自拉丁语,意思是“名称”)是一个可以按名称和地址来搜索OSM中的数据,并生成OSM点的合成地址的工具(反向地理编码).可用在http://nominatim.openstreet ...

  4. I/O流——字节流

    流的概念 流是一个很形象的概念,当程序需要读取数据的时候,就会开启一个通向数据源的流,这个数据源可以使文件,内存,或是网络连接.类似的,当程序需要写入数据的时候,就会开启一个通向目的地的流.这时候你就 ...

  5. Javascript-URL帮助类

    很久以前写的一个js关于url的帮助类,今天又翻出来了.贴一下源码,做一个简单的教程. 作用 这是一个关于urlquery的一个帮助类,我们在前端编程的时候经常涉及到操作并重组url的情况,在参数比较 ...

  6. Oracle创建用户及表空间 代码片段

    create tablespace testdatalogging datafile 'D:\oracle\oradata\orcl\testdata.dbf' size 50m autoextend ...

  7. Using FastCGI to Host PHP Applications on IIS 7 -IIS7 怎么配置 PHP5

    This article describes how to configure the FastCGI module and PHP to host PHP applications on IIS 7 ...

  8. Adobe Photoshop CS4 Extended CS4 激活序列号

    Adobe Photoshop CS4 Extended CS4 激活序列号(SN):1330-1779-4488-2103-6954-09161330-1170-1002-7856-5023-077 ...

  9. Cesium的api之关于viewer(二)

    1.构建一个viewer,如下创建:options的参数根据实际情况,进行设定 var viewer = new Cesium.Viewer('cesiumContainer', { //Start ...

  10. Android Audio 分析

    一.架构 二.MediaServer初始化 所有的media服务都在进程mediaserver里.其代码在framework/base/media/mediaserver/main_mediaserv ...