UVA 725 – Division
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
Miguel Revilla
2000-08-31 从1234到99999枚举一遍就行了。。
#include<stdio.h>
int number[];
int check(int a, int b){
if(a > )return ;
for(int i=;i< ;i++){
number[i] = ;
}
if(b<)number[] = ;
while (a){
number[a%] = ;
a /= ;
}
while (b){
number[b%] = ;
b /= ;
}
int sum = ;
for (int i=; i<; i++)
sum += number[i];
return sum == ;
}
int main() {
int ans, cnt = ;
while (scanf("%d", &ans) == , ans) {
if (cnt++) printf("\n");
int flag = ;
for (int i = ;i<;i++){
if (check(i*ans,i)){
printf("%05d / %05d = %d\n", i * ans, i, ans);
flag = ;
}
}
if (!flag) {
printf("There are no solutions for %d.\n",ans);
}
}
return ;
}
UVA 725 – Division的更多相关文章
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- 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 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- Uva 725 Division
0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
- uva 725 DIVISION (暴力枚举)
我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- UVa 725 Division (枚举)
题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0),2≤n≤79. 分析 : 最暴力的方法莫过于采用数组存 ...
随机推荐
- ThinkPHP-3.2.3学习
一.下载安装 核心包:不用解释,最减版本 完整包:包括扩展功能(验证码.session等) 二.调试 ----www ---thinkphp_3 Application ...
- Jquery中$.ajax()方法参数详解(转)
转自:http://blog.sina.com.cn/doctor830619 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数, ...
- 【集训笔记】博弈论相关知识【HDOJ 1850【HDOJ2147
以下资料来自:http://blog.csdn.net/Dinosoft/article/details/6795700 http://qianmacao.blog.163.com/blog/stat ...
- nginx记录响应与POST请求日志
生产环境中的某些api出现故障,但是问题无法重现,但是又很想解决掉问题以及我们新项目上线,需要跟踪请求与响应的信息,可以预先找到一些bug,减少大面积的损失. 安装nginx与ngx_lua 响应日志 ...
- vnc server配置、启动、重启与连接,图形管理linux系统
环境:RedHat Linux 5企业版.Xwindows:gnome (红帽默认安装的图形界面) 尽管我们可以使用SSH连接远程通过字符界面来操作Linux,但是对于更多熟悉图形人来说是很不方便的, ...
- 完整的yuicompressor单个压缩和批量压缩以及gzip再次压缩,拦截器的配置等
下载地址:http://yuilibrary.com/download/yuicompressor/ 个人认为现在yuicompressor是最安全,最值得信赖的压缩工具,至少到现在没出现过问题 1. ...
- shell中判断用法
测试结构: 测试命令可用于测试表达式条件的真假,true,则返回0,false,则返回非0:这一点c/c++有区别: 格式: test expression #expression是一个 ...
- ACM第二次比赛( C )
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Vanya ...
- javascript每日一练(十四)——弹性运动
一.弹性运动 运动原理:加速运动+减速运动+摩擦运动: <!doctype html> <html> <head> <meta charset="u ...
- 我的Python成长之路---第一天---Python基础(1)---2015年12月26日(雾霾)
2015年12月26日是个特别的日子,我的Python成之路迈出第一步.见到了心目中的Python大神(Alex),也认识到了新的志向相投的伙伴,非常开心. 尽管之前看过一些Python的视频.书,算 ...