暴力求解——除法 Division,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
解题思路:
0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据N。只要枚举fghjk就可以算出abcde,然后判断所有数字都不相同即可。 程序代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[];
int main()
{
int N,n=;
while(scanf("%d",&N)&&N)
{ int f=,fghjk;
if(n++) printf("\n");
for( fghjk= ; ;fghjk++)
{
int abcde=fghjk*N;
sprintf(s,"%05d%05d",abcde,fghjk);
if(strlen(s)>) break;
sort(s,s+);
bool b=true;
for(int i=;i<;i++)
if(s[i]!=i+'') b=false; if(b)
{
f++;
printf("%05d / %05d = %d\n",abcde,fghjk,N);
} }
if(f==) printf("There are no solutions for %d.\n",N);
}
return ;
}
暴力求解——除法 Division,UVa 725的更多相关文章
- 除法(Division ,UVA 725)-ACM集训
		参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ... 
- uva 725  Division(除法)暴力法!
		uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ... 
- 暴力枚举 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  UVA 10976 简单枚举
		UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ... 
- 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观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ... 
随机推荐
- power desinger 学习笔记<二>
			power designer 设计表时显示注释选项 PowerDesigner设计时表显示注释选项: 选定编辑的表,右键- > Properties- > Columns- > Cu ... 
- office2010怎么激活
			软件都是不断更新换代的,像我们使用最多的Microsoft Office软件,从最初的98,2000,2003,2007,到现在的2010.但是在最初安装Office软件时,都是未激活的.下面介绍的就 ... 
- Java hashCode 和 equals()
			1 Object中定义的hashCode() public int hashCode() Returns a hash code value for the object. This method i ... 
- Fedora 21 安装Infinality
			原文地址: Fedora 21 用infinality美化你的字体 http://blog.csdn.net/element207/article/details/41746683 安装infinal ... 
- php学习代码杂记
			16/2/22 字符串连接 (1)连接运算符(“.”):它返回将右参数附加到左参数后面所得的字符串. (2)连接赋值运算符(“.=”):它将右边参数附加到左边的参数后. 相当于JS里面的 += . $ ... 
- mysql数据类型——时间类型
			四种日期格式: 每个时间类型有一个有效值范围和一个"零"值,当指定不合法的MySQL不能表示的值时使用"零"值. YEAR 0000 YYYY ... 
- Python自动化运维之26、Web框架本质、MVC与MTV
			一.Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:ut ... 
- NET Core 静态文件及JS包管理器(npm, Bower)的使用
			NET Core 静态文件及JS包管理器(npm, Bower)的使用 文章目录 在 ASP.NET Core 中添加静态文件 使用npm管理JavaScript包 使用Bower管理JavaScri ... 
- BZOJ 1185 最小矩形覆盖
			Description Input Output Sample Input Sample Output HINT 其实这题就是一道旋转卡壳的裸题,但是我的精度萎了.直接上hzwer的代码吧... #i ... 
- One git command may cause you hacked(CVE-2014-9390)
			0x00 背景 CVE-2014-9390是最近很火的一个漏洞,一个git命令就可能导致你被黑,我不打算深入探讨这个漏洞的细节,官方已经在https://github.com/blog/1938-gi ... 
