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. Mysql 创建联合主键

    Mysql 创建联合主键2008年01月11日 星期五 下午 5:21使用primary key (fieldlist)      比如:   create table mytable (       ...

  2. iOS9 白名单问题 -canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query for scheme xx"

    [iOS开发]-canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query fo ...

  3. 3.3 用NPOI操作EXCEL--生成一张工资单

    这一节,我们将综合NPOI的常用功能(包括创建和填充单元格.合并单元格.设置单元格样式和利用公式),做一个工资单的实例.先看创建标题行的代码: //写标题文本 HSSFSheet sheet1 = h ...

  4. mac 上搭建SVN

    copy from 广东小码哥,M了个J. 在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境.在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装 ...

  5. F - 蜘蛛牌(深度搜索)

    Problem Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么 ...

  6. HDU 2023题解分析

    我想说这道题我还没弄明白我错哪了,交了20多遍一直都是Runtime Error,改了N次还是不对,后来搜了一下,说是数组开小了,又把数组开大,还不对,又改发现一个平均值求错,再改,还不对,洗洗睡吧. ...

  7. [C#]窗体切换--避免开启多个线程

    先说说这个多窗体的界面的解决的办法: 用到的方法很简单,就是程序运行就建立一个MainForm,在这个MainForm中设立一个Panel,同时设立几个按钮,按下每个按钮都在这个Panel中载入不同的 ...

  8. SQLSERVER 跨服务器查询

    SELECT * FROM OPENDATASOURCE(         'SQLOLEDB',         'Data Source=IP;User ID=UserId;Password=Pa ...

  9. javascript 学习随笔7

    <head> <title>标题页-学无忧(www.xue51.com)</title> <script language="JavaScript& ...

  10. [LeetCode]题解(python):015-3Sum

    题目来源: https://leetcode.com/problems/3sum/ 题意分析: 这道题目是输入一个数组nums.找出所有的3个数使得这3个数之和为0.要求1.输出的3个数按小到大排序, ...