UVa 725暴力求解
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
#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暴力求解的更多相关文章
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- uva 725 Division(除法)暴力法!
uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- 除法(Division ,UVA 725)-ACM集训
参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
随机推荐
- 带你走进EJB--MDB
在之前的文章中我们介绍了带你走进EJB--JMS 和 带你走进EJB--JMS编程模型 对JMS有了初步的了解, 作为EJB系列的文章我们会继续对EJB相关的内容做进一步深的学习和了解.而此次需要进行 ...
- js调用.net后台
<head runat=server> <script type="text/javascript"> $(function () { var js_tim ...
- 由命名空间函数而引发思考--js中的对象赋值问题
最近没有编码任务,作为一个才毕业的小辣鸡,给的任务就是看一下公司的新系统,熟悉怎么用哪些地方是干什么的. 下午喝了两杯水,感觉有点浪.然后就开始看了下代码.发现有一个函数是这样子的. var TX = ...
- 编译kernel:make Image uImage与zImage的区别
make Image uImage与zImage的区别 http://blog.chinaunix.net/uid-25322094-id-3589796.html 内核编译(make)之后会生成两 ...
- Notepad++中Windows,Unix,Mac三种格式
Notepad++中Windows,Unix,Mac三种格式之间的转换 http://www.crifan.com/files/doc/docbook/rec_soft_npp/release/htm ...
- STL之vector(向量)
C++编程语言中有一种叫做Vector的应用方法,它的作用在实际编程中是非常重要的,这里详细介绍一下C++ Vector的相关应用技巧及基本内容: Construct vector #include ...
- Nginx 之一:编译安装nginx 1.8.1 及配置
一:基介绍 官网地址www.nginx.org,nginx是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间 ...
- MVCC 多版本并发控制
关于事务的介绍暂且不谈. InnoDB行级锁,虽然在很大程度上提高了事务的并发性,但是终究还是要耗费很大的.为了更进一步的提高并发性同时降低开销,存储引擎会同时实现MVCC. InnoDB实现MVCC ...
- 转:按需加载html 图片 css js
按需加载是前端性能优化中的一项重要措施,按需加载是如何定义的呢?顾名思义,指的是当用户触发了动作时才加载对应的功能.触发的动作,是要看具体的业务场景而言,包括但不限于以下几个情况:鼠标点击.输入文字. ...
- cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(二)
在了解地图的初始化和加载之前,我们先了解下mario的地图. 用tiled工具打开mario地图 从地图中可以看到,mario的地图有很多层构成: objects层:怪物,会动的怪物 coin层:金币 ...