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观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
随机推荐
- 84. 从视图索引说Notes数据库(下)
作用和代价上文介绍了关系型数据库里的索引.Notes数据库里的索引隐藏在视图概念里(本文的讨论仅仅针对Notes的视图索引,不包括全文索引.).开发者创建的视图仅仅是存放在数据库里的一条设计文档.数据 ...
- nyoj-709-异形卵(水题)
异 形 卵 时间限制:1000 ms | 内存限制:65535 KB 难度: 描写叙述 我们探索宇宙,是想了解浩瀚星空的奥妙.但我们却非常少意识到宇宙深处藏匿的危急,它们无时无刻不紧盯着我们的地球 ...
- String、StringBuffer、StringBuilder之间区别
String,StringBuffer,StringBuilder 之间区别 在字符串处理中C#提供了String.StringBuffer.StringBuilder三个类.那么他们到底有什么优缺点 ...
- 如何让HTML的编写更具结构性
首先声明,我不是搞技术的,很多词汇写的不够专业,但作为一枚菜鸟,我站在菜鸟的角度,来讲述我在学习技术的过程中所遇到的问题,和解决的方案. 入门HTML还算简单,无非是先写好固定的三对开闭标签结构:ht ...
- VS快捷键简单记录
代码上下移动行:Alt+上下键 跳转相等大括号:Ctrl+]
- Tomcat7.0.22在Windows下详细配置过程
Tomcat7.0.22在Windows下详细配置过程 一.JDK1.7安装 1.下载jdk,下载地址:http://www.oracle.com/technetwork/java/javase/do ...
- dedecms的入门使用
前段时间(其实也很远了)一直在学习dedecms,这里对前段时间的学习做一个总结. dedecms学习网址:http://help.dedecms.com/v53
- js中访问对象的方法
如果在js中定义了一个变量obj1,如 var obj1 = 234; 那么访问这个边个两的方式至少有两种, 1 window["obj1"],那么值为234, 2 var tar ...
- Android的AsyncTask类的解读
国庆节放假.搞了半个月都没有上班了,coding的时候一点都不在状态,本来这篇文章是在国庆节前写完的,可是由于自己的懒 惰,导致延期到国庆节,哎,这种习惯真心不好呀...不多说了以下来进入正题 之前我 ...
- android代码实现关机
1.API没有开放,需要提升为syetem app级别! 2.android 模块编译,mm 命令 2.1.先进入顶层 source build/envsetup.sh 2.2.进入目录 m ...