uva 725  Division(除法)

A - 暴力求解

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 

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 . 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
题意:
输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a—j恰好为数字0—9的一个排列(可以有0前导)  2=<n<=79
思路:

可以用五层循环,但是过程有些繁琐
也可只枚举fghij就可以算出abcde,然后判断符不符合条件。
#include<stdio.h>
int p[];
int juge(int a, int b) //判断出符合条件的a,b,把a,b每一位都标记一次
{
if (a > )
return ;
for (int i = ; i < ; i++)
{
p[i] = ;
}
if (b<)
p[]=;
while(a)
{
p[a%] = ; //判断每一位,然后标记
a/= ;
}
while(b)
{
p[b%] = ;
b/=;
}
int total = ;
for (int i = ; i < ; i++)
total+=p[i];
return total==; //直到有符合条件的不同的十个数字
}
int main()
{
int n, m = ;
while (scanf("%d", &n) == , n)
{ if (m>) printf("\n");m++; //输出格式要求
int f = ;
for (int i = ; i < ; i++) //范围应该很好想出
{
if (juge(i*n,i))
{
printf("%d / %05d = %d\n", i*n,i,n); //格式控制输出,五位数如果缺就用0补上
f =;
}
}
if (f)
{
printf("There are no solutions for %d.\n",n);
}
}
return ;
}

uva 725 Division(除法)暴力法!的更多相关文章

  1. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  2. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  3. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  4. UVA.725 Division (暴力)

    UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...

  5. uva 725 DIVISION (暴力枚举)

    我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...

  6. UVa 725 Division (枚举)

    题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0),2≤n≤79. 分析 : 最暴力的方法莫过于采用数组存 ...

  7. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  8. uva 725 division(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

  9. UVA 725 – Division

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

随机推荐

  1. Java系统变量设置方式

    近期碰到一个编码的问题,发现整个平台都是用的GB2312,因此导致webservice调用时有些字不能正常接受. 反编译中间件的源码如下: public static final String nod ...

  2. I - Fire Game

    题目大意: 火焰游戏 在一个];][] = { {,},{,},{-,},{,-} };; i<M; i++)    ; j<N; j++)    {        )           ...

  3. Tips--8080端口被占用了怎么办

    下面以win7为例: 打开任务管理器   ctrl+alt+. 找到8080端口对应的PID 停止相应PID的进程即可:

  4. Atom 编辑器 前端基本插件

    Atom 编辑器插件 这个编辑器是github出品,现在处于免费试用期:如果是初学者,可以使用这个编辑器,插件安装很方便,只需要点菜单栏的File-Settings-Install,在搜索框中输入想要 ...

  5. Android Bitmap开发之旅--基本操作

    1 Bitmap加载方式 在介绍Bitmap--OOM 异常时,首先介绍一下Bitmap有哪几种加载方式.通常Bitmap的加载方式有Resource资源加载.本地(SDcard)加载.网络加载等加载 ...

  6. Qt 学习之路 :Qt 线程相关类

    希望上一章有关事件循环的内容还没有把你绕晕.本章将重新回到有关线程的相关内容上面来.在前面的章节我们了解了有关QThread类的简单使用.不过,Qt 提供的有关线程的类可不那么简单,否则的话我们也没必 ...

  7. Qt 学习之路:QFileSystemModel

    上一章我们详细了解了QStringListModel.本章我们将再来介绍另外一个内置模型:QFileSystemModel.看起来,QFileSystemModel比QStringListModel要 ...

  8. MaxReceivedMessageSize :已超过传入消息(65536)的最大消息大小配额

    做的windows应用程序(后台调用webservice),数据量大的时候,报错如下: System.ServiceModel.CommunicationException: 已超过传入消息(6553 ...

  9. React Native 从入门到原理

    React Native 是最近非常火的一个话题,介绍如何利用 React Native 进行开发的文章和书籍多如牛毛,但面向入门水平并介绍它工作原理的文章却寥寥无几. 本文分为两个部分:上半部分用通 ...

  10. Linux字符串函数集

    //Linux字符串函数集: 头文件:string.h 函数名: strstr 函数原型:extern char *strstr(char *str1, char *str2); 功能:找出str2字 ...