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
题意:输入一个数n,从小到大输出它的abcde / fghij = n的类型的式子(注意空格,可以有前导0)a-j是一个0到9的排列。如果没有则输出There are no solutions for 61. 格式要求:每测试一组案例,换一空行。(这输出格式也是RLGL)
解题思路:枚举,但是是从被除数枚举,通过相乘算出除数。然后就只需要判断除数是否大于100000,a-j是否相等。
代码如下:(本来想自己写的,就是自己不会用标记,最后还是没有坚持下来,还是看了别人的博客,然后仿写了。)
想问个问题,用 memse(m,0,sizeof(m)) 清零数组m,为什么一定是sizeof(m), 不可以用m的长度10,因为当我用10的时候就连案例都通不过了....
求告知,没错我就是这么菜.....(⊙﹏⊙)b
#include <stdio.h>
#include <cstring>
int m[];
int panduan(int a,int b)
{
if(a>)
return ;
memset(m,,sizeof(m));
//for(int i=0;i<10;i++)
// m[i]=0;
if(b<)
m[]; //容易忘记 while(a)
{
m[a%]=; //每一位都标记
a=a/; //标记了就除掉一位
}
while(b)
{
m[b%]=;
b=b/;
}
int sum=;
for(int j=; j<; j++)
sum+=m[j];
return sum==; //当sum等于10才返回
}
int main()
{
int n,k=;
while(scanf("%d",&n)==&&n)
{
if(k>) printf("\n"); k++; //输出格要求
int flag=;
for(int i=; i<; i++)
{
if(panduan(n*i,i))
{
printf("%d / %05d = %d\n",i*n,i,n);
flag=;
}
}
if(flag)
printf("There are no solutions for %d.\n",n); }
return ;
}
UVA 725的更多相关文章
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- 除法(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 (暴力)
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判断是否符合题目条件 ...
- Uva 725 Division
0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
- Uva 725 除法
紫书P182 直接枚举 0~9 的全排列会超时,枚举fghij就可以了,计算出 abcde ,这里有一个新的函数,也可以不用咯,把每一位数据提取出来,while循环可以做到,这里的新的函数是,spri ...
随机推荐
- PHP读书笔记(5)-结构语句
PHP结构语句 顺序结构 顺序结构就像一条直线,按着顺序一直往下执行.我们编写的代码默认都是按照顺序结构执行的. 条件结构之if…else… 条件结构就像一个岔路口,可以向左走,也可以向右走.比如上洗 ...
- 查看Oracle执行计划的几种方法
查看Oracle执行计划的几种方法 一.通过PL/SQL Dev工具 1.直接File->New->Explain Plan Window,在窗口中执行sql可以查看计划结果.其中,Cos ...
- gitlab备份与恢复操作方法
github私有仓库是收费的,有些代码不方便托管到外面的git仓库,因此就产生了自己搭建git服务器的需求. 好在有广大的开源人士的贡献,有了gitlab这一神器. 手动配置较多,直接用集成包: bi ...
- 接收POst数据流数据
var data = ""; using (StreamReader readStream = new StreamReader(context.Re ...
- 关于启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!
- 【原】web服务器占有量统计等 web网站
根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中 1. https://w3techs.com/ nginx 中文站 2. http://www.nginx.cn/doc/
- extjs的调试方法
1.使用extjs自带的测试工具 第一步:在ExtJS下载的资源包中,找到debug.js,将JS文件导入实际要运行的HTML或者JSP页面上 第二步:在有关JS文件代码中嵌入Ext.log('自定义 ...
- ActiveMQ(5.10.0) - hello world
Sending a JMS message public class MyMessageProducer { ... // 创建连接工厂实例 ConnectionFactory connFactory ...
- Java加密解密相关
关于解释加密解密中的填充方案: http://laokaddk.blog.51cto.com/368606/461279/ 关于对称加密中的反馈模式: http://blog.csdn.net/aaa ...
- money 转换成 varchar
Sql :cast(sum(colname) as varchar) 或者 convert(varchar,sum(colname)) ),sum(colname))