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 ...
随机推荐
- jQuery数组处理
1. $.each(array, [callback]) 遍历[常用] 解释: 1.不同于例遍 jQuery 对象的 $().each() 方法,此方法可用于例遍任何对象(不仅仅是数组哦~). 2.回 ...
- 解决Android&eclipse无法RunAs的问题
application不能运行,console显示 The connection to adb is down, and a severe error has occured. You must re ...
- alfresco 5.0 document
http://docs.alfresco.com/community/tasks/imagemagick-config.html
- [转].NET进阶系列之一:C#正则表达式整理备忘
本文转自:http://www.cnblogs.com/KissKnife/archive/2008/03/23/1118423.html 有一段时间,正则表达式学习很火热很潮流,当时在CSDN一天就 ...
- Java Classloader原理分析
类的加载过程指通过一个类的全限定名来获取描述此类的二进制字节流,并将其转化为方法区的数据结构,进而生成一个java.lang.Class对象作为方法区这个类各种数据访问的入口.这个过程通过Jav ...
- ubuntu qt :-1: error cannot find lgl
安装package "libgl1-mesa-dev": sudo apt-get install libgl1-mesa-dev 参考文献: Qt: can't find -lG ...
- poj1472[模拟题]
Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2017 Accepted: 698 ...
- TSQL基础(一) - 查询
select 1.查询一张表(orders)的所以纪录 select * from Orders 2.查询一张表(orders)某字段的所有记录 select OrderID,OrderDate fr ...
- html 文件动态加载.PDI 流程图
1 //javascript脚本 <script> window.onload = function () { var aid = document.getElementById(&quo ...
- 第四十五篇、UITableViewCell高度计算
由于tableView:heightForRowAtIndexPath:方法的调用频率非常高,如果将cell高度的计算过程放在此方法中,那么效率将会非常的低,快速tableview就会出现卡顿 1.通 ...