参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html

算法学到很弱,连这么简单个问题都难到我了。但我偏不信这个邪,终于做出来了。不过,是参照别人的,是 xiaobaibuhei 到博客让我找到到感觉,不过我只看了一遍他到代码,后面都是自己写的,虽然写的很像。。。

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
//============================================================================
// Name : uva 725
// Author : lvyahui
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <cstdio>
#include <list>
#include <cstring>
using namespace std; char str[10];
bool val[10]; bool check(int a,int b){
bool isok = true;
sprintf(str,"%05d%05d",a,b);
memset(val,false,sizeof(val));
for (int i = 0; i < 10; ++i) {
if(val[str[i]-'0']){
isok = false;break;
  }
val[str[i]-'0'] = true;
}
return isok;
}
int main() {
int n; memset(val,0,sizeof(val));
scanf("%d",&n);
int b;
bool hasans = false;
for(int a=1234;a < 49383;a++){// b最大到98765 除2就是49383
// b / a = n
b = a * n;
if(b >= 98765){
break;
}
if(check(a,b)){
printf("%05d / %05d = %d\n",b , a , n);
if(!hasans){
hasans = true;
}
}
}
if(!hasans){
printf("There are no solutions for %d",n);
}
return 0;
}

除法(Division ,UVA 725)-ACM集训的更多相关文章

  1. 暴力求解——除法 Division,UVa 725

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

  2. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  3. 暴力枚举 UVA 725 Division

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

  4. uva 725 Division(暴力模拟)

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

  5. UVA.725 Division (暴力)

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

  6. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  7. yzm10的ACM集训小感

    7月30号,ACM集训进行了两周,一切都已on the right way.这时的我适时地从题海中探出头,其实除了刷题,也该写点什么来总结下过去.首先,在第一周里,我学习了数据结构,知道了STL这么一 ...

  8. Uva 725 Division

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

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

随机推荐

  1. 《A First Course in Probability》-chaper3-条件概率和独立性-P(·|F)是概率

    条件概率中的三个命题: 下面我们分条来解读一下这三个命题.

  2. Centos6.4 cobbler安装要点

    1,yum 安装cobbler rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm y ...

  3. 宁波Uber优步司机奖励政策(1月18日~1月24日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  4. cf493A

    Description Vasya has started watching football games. He has learned that for some fouls the player ...

  5. 获取文件路径 分类: WinForm 2014-07-25 14:27 103人阅读 评论(0) 收藏

    //可获得当前执行的exe的文件名. string str1 =Process.GetCurrentProcess().MainModule.FileName; //获取和设置当前目录(即该进程从中启 ...

  6. 教你Mac OS系统四种改动Hosts文件的方法

    使用Mac OS X系统的用户.在某些时候可能遇到了须要改动系统Hosts文件的情况,那么Mac OS系统怎样改动Hosts文件呢?和Windows系统有何差别呢?我们知道事实上改动Hosts文件仅仅 ...

  7. docker 服务注册

    docker 服务注册 etcd docker run -d --name etcd -p 4001:4001 -p 7001:7001 elcolio/etcd

  8. ||和 && 符号的赋值运用(转)

    javascript “||”.“&&”的灵活运用 博客分类: Jquery javascript javascript中运用“||”.“&&”javascript 真 ...

  9. char* 和char[]的差别

    下面内容均来自互联网,系笔者汇总并总结. 1. 问题介绍 问题引入: 在实习过程中发现了一个曾经一直默认的错误,相同char *c = "abc"和char c[]="a ...

  10. 使用AVCaptureSession捕捉静态图片

    #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> #import <AssetsLibrary/ ...