uva 725 Division(除法)暴力法!
uva 725 Division(除法)
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
题意:
输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a—j恰好为数字0—9的一个排列(可以有0前导) 2=<n<=79
思路: 可以用五层循环,但是过程有些繁琐
也可只枚举fghij就可以算出abcde,然后判断符不符合条件。
#include<stdio.h>
int p[];
int juge(int a, int b) //判断出符合条件的a,b,把a,b每一位都标记一次
{
if (a > )
return ;
for (int i = ; i < ; i++)
{
p[i] = ;
}
if (b<)
p[]=;
while(a)
{
p[a%] = ; //判断每一位,然后标记
a/= ;
}
while(b)
{
p[b%] = ;
b/=;
}
int total = ;
for (int i = ; i < ; i++)
total+=p[i];
return total==; //直到有符合条件的不同的十个数字
}
int main()
{
int n, m = ;
while (scanf("%d", &n) == , n)
{ if (m>) printf("\n");m++; //输出格式要求
int f = ;
for (int i = ; i < ; i++) //范围应该很好想出
{
if (juge(i*n,i))
{
printf("%d / %05d = %d\n", i*n,i,n); //格式控制输出,五位数如果缺就用0补上
f =;
}
}
if (f)
{
printf("There are no solutions for %d.\n",n);
}
}
return ;
}
uva 725 Division(除法)暴力法!的更多相关文章
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- uva 725 DIVISION (暴力枚举)
我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...
- UVa 725 Division (枚举)
题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0),2≤n≤79. 分析 : 最暴力的方法莫过于采用数组存 ...
- Uva 725 Division
0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
- UVA 725 – Division
Description Write a program that finds and displays all pairs of 5-digit numbers that between them ...
随机推荐
- jsp中的contentType与pageEncoding的区别和作用
jsp中的contentType与pageEncoding的区别和作用 <%@ page contentType="text/html; charset=utf-8" p ...
- poj 3903 最长上升子序列 Stock Exchange
题目链接:http://poj.org/problem?id=3903 #include <cstdio> #include <cmath> #include <algo ...
- HAProxy、Nginx 配置 HTTP/2 完整指南
基于最近对HTTP/2的争论和它的优势,是时候升级底层架构了.这篇文章将会介绍如何在安装和配置HAProxy和Ngnix(使用ssl终端).为了简化流程,我建议你准备好使用Docker镜像. 如果你想 ...
- servlet简介
web 开发分为两种:静态开发(使用html)和动态开发(使用servlet/jsp,jsp就是servlet,ASP ,PHP) 所以servlet是sun公司提供的一门专门用于开发动态web资源的 ...
- 项目经历——EasyUI的检索和更新操作
什么事都耐不住“磨”?! 比如一个让人很头疼的问题,对于项目中所用到的EasyUI框架就是一个很明显的感受.项目使用的EasyUI框架,自身封装好的样式使得开发者不用考虑具体的div和css样式了,但 ...
- Axure7.0.0.3155注册码
Licence:aaa Key1:h624pifAqt7It5e8boKkML+Y4RjDX5xknP4k7QktJYQoxsvv7VUS7hBCv/2ef45P Key2:2GQrt5XHYY7SB ...
- Hibernate Criterion
在查询方法设计上能够灵活的依据Criteria的特点来方便地进行查询条件的组装.Hibernate设计了CriteriaSpecification作为Criteria的父接口,以下提供了Criteri ...
- Amoeba for MySQL 非常好用的mysql集群软件
http://docs.hexnova.com/amoeba/ Amoeba for MySQL致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当query 路由功能,专 ...
- std::bad_alloc
一个服务器程序,长时间运行报错了. ----------- terminate called after throwing an instance of 'std::bad_alloc' what() ...
- Java基础知识强化17:JAVA不可以将所覆盖的方法的访问权限变得比父类的小
首先我们看一下下面的代码如下: interface I { void go(); } abstract class A implements I { } class C extends A { voi ...