uva 725  Division(除法)

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
题意:
输入正整数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(除法)暴力法!的更多相关文章

  1. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  2. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  3. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  4. UVA.725 Division (暴力)

    UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...

  5. uva 725 DIVISION (暴力枚举)

    我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...

  6. UVa 725 Division (枚举)

    题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0),2≤n≤79. 分析 : 最暴力的方法莫过于采用数组存 ...

  7. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  8. uva 725 division(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

  9. UVA 725 – Division

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

随机推荐

  1. [Locked] Group Shifted Strings

    Group Shifted Strings Given a string, we can "shift" each of its letter to its successive ...

  2. javax.el.PropertyNotFoundException错误

    在J2EE项目的开发过程中,遇到了这个问题,报错如下: 错误原因为在我model里的Person类里定义了一个Name属性,但是读取属性的getter方法的,一般按照属性首字母小写来处理,所以把Nam ...

  3. Linux散列表(二)——宏

    散列表宏承接了双向链表宏的风范,好使好用!务必区分“结点”和“元素”!双链表宏博文中已经提及,这里不赘述! 1.获取元素(结构体)基址 #define hlist_entry(ptr, type, m ...

  4. Linux Epoll介绍和程序实例

    Linux Epoll介绍和程序实例 1. Epoll是何方神圣? Epoll但是当前在Linux下开发大规模并发网络程序的热门人选,Epoll 在Linux2.6内核中正式引入,和select类似, ...

  5. android蓝牙4.0(BLE)开发之ibeacon初步

    一个april beacon里携带的信息如下 ? 1 <code class=" hljs ">0201061AFF4C0002159069BDB88C11416BAC ...

  6. (五)带属性值的ng-app指令,实现自己定义模块的自己主动载入

    如今我们看下怎样使用带属性值的ng-app命令,让ng-app自己主动载入我们自己定义的模块作为根模块. <!DOCTYPE html> <html> <head> ...

  7. STL——静态常量整数成员在class内部直接初始化

    如果class内含const static integral data member,那么根据C++标志规格,我们可以在class之内直接给予初值.所谓integral泛指所有的整数型别(包括浮点数) ...

  8. dede 标签调用

    调用当前栏目名字 {dede:type}[field:typename /]{/dede:type} 调用某栏目名字 {dede:type typeid='1'}[field:typename /]{ ...

  9. Lock锁_线程_线程域

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  10. Android设计图(标注、切图)

    1.Android: 1)Android的单位是dp 2)分为ldpi/mdpi/hdpi/xhdpi/xxhdpi. 3)分辨率对应DPI ldpi  QVGA (240×320) mdpi  HV ...