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

Miguel Revilla
2000-08-31
程序分析:此题的意思就是输入正整数N,按从小到大的顺序输出所有形如abcde/ fghij=N的表达式,其中a~j恰好为数字0-9的一个排列(可以有前导0),2<=N<=79.在这里我们需要使用暴力法,枚举0-9
的所有排列?没这个必要,也会超时。所以只需要枚举fghij就可以算出abcde,然后判断是否所有数字都不相同即可。不仅程序简单,而且枚举量也从10!=3628800降低至不到1W而且当abcde和fghij加起来超过10位即可以终止枚举
程序代码:
#include<stdio.h>
int number[15];
int check(int a, int b) {
if (a > 98765) return 0;
for (int i = 0; i < 10; i++) {
number[i] = 0;
}
if (b < 10000) number[0] = 1;
while (a) {
number[a % 10] = 1;
a /= 10;
}
while ( b ) {
number[b % 10] = 1;
b /= 10;
}
int sum = 0;
for (int i = 0; i < 10; i++)
sum += number[i];
return sum == 10;
}
int main() {
int ans, cnt = 0;
while (scanf("%d", &ans) == 1, ans) {
if (cnt++) printf("\n");
int flag = 0;
for (int i = 1234; i < 99999; i++) {
if (check(i * ans, i)) {
printf("%05d / %05d = %d\n", i * ans, i, ans);
flag = 1;
}
}
if (!flag) {
printf("There are no solutions for %d.\n",ans);
}
}
return 0;
}
 

UVa 725暴力求解的更多相关文章

  1. 暴力枚举 UVA 725 Division

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

  2. uva 725 Division(暴力模拟)

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

  3. UVA.725 Division (暴力)

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

  4. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  5. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  6. 除法(Division ,UVA 725)-ACM集训

    参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...

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

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

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

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

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

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

随机推荐

  1. javascript中处理引号编码&#034;

    1. <c:out value='${jxOrgJsonStr}' escapeXml="false"/> 2.或者使用innerText 直接接受${jxOrgJso ...

  2. debian安装vld来查看Opcode,PHP调优。

    一: 我的环境: Debian 7 (wheezy)  x64 PHP 5.4.4-14 (apt-get 而来) Apache/2.2.22 (同上,非源码编译) 二 :安装vld. (# 代表是r ...

  3. android点滴之PendingIntent的使用

    一概念 PendingIntent就是一个能够在满足一定条件下运行的Intent,它相比于Intent的优势在于自己携带有Context对象.这样他就不必依赖于某个activity才干够存在. 它和I ...

  4. CSS引入的方式有哪些? link和@import的区别是?转载

    CSS引入的方式有哪些? link和@import的区别是? HTML 中引入 CSS 的方式 有 4 种方式可以在 HTML 中引入 CSS.其中有 2 种方式是在 HTML 文件中直接添加 CSS ...

  5. 2.3.9 用NPOI操作EXCEL--通过NPOI获得公式的返回值

    前面我们学习了通过NPOI向Excel中设置公式,那么有些读者可能会问:“NPOI能不能获取公式的返回值呢?”,答案是可以!一.获取模板文件中公式的返回值如在D盘中有一个名为text.xls的Exce ...

  6. Oracle中的EXCEPTION

    Oracle系统预定义的异常 比如:SELF_IS_NULL.VALUE_ERROR.ZERO_DIVIDE等Oracle中自带的异常类型 使用方法: DECLARE V_Result ); BEGI ...

  7. TC基础使用指南(基于xbeta的TC配置文件)

    所有常用目录都可以通过ctrl+d加一个或几个字母的超快捷方式直接跳转到位. 按下BackSpace键,就可以进入到上一级目录 Ctrl+q 在右侧打开左侧选定文件,再按一次Ctrl+q退出 按 Ct ...

  8. Visual Studio调试技巧 -- Attach to Process #Reprinted#

    from:http://www.cnblogs.com/lyosaki88/p/3481338.html 一般写完代码时,我们通常会启动调试运行一下看看是否正确,启动运行的方式无非是F5-- Star ...

  9. cocos2d-x游戏开发系列教程-超级玛丽08-消息机制

    在超级玛丽游戏里,地图类CMGameMap负责所有的程序逻辑,它包含了背景地图,包含了游戏元素精灵,当游戏中的精灵之间发生碰撞时,比如马里奥撞上砖头这种事情发生时,马里奥对象本身不知道怎么处理这个逻辑 ...

  10. 国际名品SYSTEM入驻北京金融街购物中心__购物败家_YOKA时尚网

    国际名品SYSTEM入驻北京金融街购物中心__购物败家_YOKA时尚网 国际名品SYSTEM入驻北京金融街购物中心