参考: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. 【PHP】php+txt实现网页计数器(限IP统计方式和不限IP统计方式)

    一般的网页计数器制作实现思路:首先设定存放统计数据的文件(counter.txt)——读取文件中的内容存入字符串——自加操作——以写入方式打开文件写入数据——从文件中输出统计数据——关闭文件. 代码: ...

  2. STL之deque、queue、stack、list

    首先deque和vector是很像的 但是de代表double双向的队列那么deque可以从首部添加(删除)元素也可以从尾部添加(删除)元素. .push_back(elem) .push_front ...

  3. 利用Trie树对字符串集合进行排序并计算特征值

    该算法用于将一组乱序的字符串反序列化到一个Trie树中,这个过程即可视为对字符串进行了一次排序. 还可以通过调用 GetFeatureString 将该 Trie 树重新序列化. #include & ...

  4. poj 1696 Space Ant 极角排序

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  5. 自主架设VOIP系统

    my.oschina.net/fcboys/blog/2695 FXS (Foreign Exchange Station) FXS is an interface which drives a te ...

  6. centos平台openstack spice配置

    配置过程只涉及控制节点(192.168.209.11)和计算节点(192.168.209.31),根据情况修改为实际环境的IP地址.     修改控制节点 安装软件包 yum install spic ...

  7. 开启gdb调试功能

    设置/etc/yum.repos.d/CentOS-Debuginfo.repo,修改[debug项下的enabled的值为1];

  8. MySQL Workbench类型之MySQL客户端工具的下载、安装和使用

    本博文的主要内容有 .MySQL Workbench的下载 .MySQL Workbench的安装 .MySQL Workbench的使用 个人推荐,比较好的MySQL客户端工具 注意啊! 对于noi ...

  9. 佛山Uber优步司机奖励政策(1月18日~1月24日)

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

  10. Python基础知识---字典

    现在在实习期间,好久没用Python了,今天在做Java项目时用的HashMap让我联想到了Python中的字典,就写一些Python字典的知识吧,复习复习. 字典:  key --> valu ...