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 ...
随机推荐
- NODE编程(三)--构建Node Web程序1
一.HTTP服务器的基本知识 1.Node如何向开发者呈现HTTP请求 Node中的http模块提供了HTTP服务器和客户端接口: var http = require('http'); 创建HTTP ...
- ArcMap运行时出现Runtime Error错误的解决方案
运行ArcMap时弹出错误提示:“Microsoft Visual C++ Runtime Library. Runtime 1.开始->运行->regsvr32 "C:\Pro ...
- JSON 日期格式问题 /Date(1325696521000)/
json返回的日期格式/Date(1325696521000)/,怎么办? Controller返回的是JsonResult对象就会导致出现这样的格式: /Date(1325696521000)/ p ...
- s实现指定时间自动跳转到某个页面
--js实现指定时间自动跳转到某个页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- [转]关于ASP.NET(C#)程序中TEXTBOX下动态DIV跟随[AJAX应用]
本文转自:http://blog.csdn.net/lolenboy/article/details/1665814 说明: 环境:ASPNET(c#),SQL2K 事例:TEXTBOX下跟随DIV, ...
- merge into update
如果要DML实现真正意义上的并发,在开始执行需要并发语句前,需要执行开启session并发 ALTER SESSION ENABLE PARALLEL DML; 在执行完语句后,需要执行关闭ses ...
- 老男孩-金角大王-python学习博客地址
http://www.cnblogs.com/alex3714/category/770733.html
- namenode无法启动(namenode格式化失败)
格式化namenode root@node04 bin]# sudo -u hdfs hdfs namenode –format 16/11/14 10:56:51 INFO namenode.Nam ...
- mysql 打包表在phpmyadmin提示正在使用中..
一,利用phpmyadmin修改表功能,REPAIR TABLE `你的表名` 或直接在数据库管理界面,选中表如下图 二,如果利用修改功能失败了我们还可以尝试在替换本地mysql数据库时,我们先停止m ...
- Objective-C 【在手动内存管理中如何写set方法】
------------------------------------------- set方法的内存管理 代码: #import <Foundation/Foundation.h> @ ...