紫书P182

直接枚举 0~9 的全排列会超时,枚举fghij就可以了,计算出 abcde ,这里有一个新的函数,也可以不用咯,把每一位数据提取出来,while循环可以做到,这里的新的函数是,sprintf(buf,"%5d%5d",abcde,fghij); 格式化提取,把abcde,fghij每一位提取到字符串buf中,不足5位的补0。然后看每一个位是否都有。都有就是一个0~9的全排列。

/*#include <stdio.h>
#include <algorithm> using namespace std; int main()
{
int n;
int a[10] = {0,1,2,3,4,5,6,7,8,9};
while(scanf("%d",&n),n) { bool flag = false;
do { int s = 0;
for(int i=0;i<5;i++) {
s = s*10 + a[i];
}
int t = 0;
for(int i=5;i<10;i++) {
t = t*10 + a[i];
}
if(s%t==0&&s/t==n) {
flag = 1;
printf("%d%d%d%d%d / %d%d%d%d%d = %d\n",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],n);
} }while(next_permutation(a,a+10)); if(!flag)
printf("There are no solutions for %d.\n",n); } return 0;
}
*/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int main() { //freopen("in.txt","r",stdin);
int n;
int kase = ;
char buf[];
while(scanf("%d",&n),n) { if(kase++)
printf("\n");
int cnt = ;
for(int fghij = ;;fghij++) {
int abcde = fghij*n;
sprintf(buf,"%05d%05d",abcde,fghij);
if(strlen(buf)>) break;
sort(buf,buf+);
bool ok = true;
for(int i=;i<;i++) {
if(buf[i]!=''+i) ok = false;
} if(ok) {
cnt++;
printf("%05d / %05d = %d\n",abcde,fghij,n);
} }
if(!cnt)
printf("There are no solutions for %d.\n",n); } return ;
}

Uva 725 除法的更多相关文章

  1. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  2. 除法(Division ,UVA 725)-ACM集训

    参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...

  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. 暴力求解——除法 Division,UVa 725

    Description Write a program that finds and displays all pairs of 5-digit numbers that between them u ...

  8. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  9. uva 725 division(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

随机推荐

  1. NSMutableDictionary中元素替换

    NSMutableDictionary *dic = [NSMutableDictionary new]; [dic addEntriesFromDictionary:@{@"key&quo ...

  2. mysql错误日志路径

    造成该问题的原因有很多,单纯的百度google这个问题,很难找到正确的解决办法,要对症下药测才能解决:1.查看具体错误信息:  按:计算机管理——>系统工具——>事件查看器——>Wi ...

  3. URAL 1018 Binary Apple Tree(树DP)

    Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a bina ...

  4. struts文件上传(单文件)

    第01步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  5. MVC4中给TextBoxFor设置默认值和属性

    例如:(特别注意在设置初始值的时候 Value 中的V要大写) @Html.TextBoxFor(model => model.CustomerCode, new { Value="  ...

  6. js 实现精确加减乘除

    //加法 function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1] ...

  7. 广告点击率 CTR预估中GBDT与LR融合方案

    http://www.cbdio.com/BigData/2015-08/27/content_3750170.htm 1.背景 CTR预估,广告点击率(Click-Through Rate Pred ...

  8. 省市区三级联动(二)JS部分简单版

    通过对上一篇<省市区三级联动>的学习发现JScript部分省市区的填充代码几乎相同,所以可以写成一个函数. 注意:html部分和chuli.php部分不变 1.下拉列表填充可以写成带参数的 ...

  9. 如何对HashMap按键值排序

    Java中HashMap是一种用于存储“键”和“值”信息对的数据结构.不同于Array.ArrayList和LinkedLists,它不会维持插入元素的顺序. 因此,在键或值的基础上排序HashMap ...

  10. ubuntu修改文件权限记录

    查看文件权限的命令: 在终端输入: ls -l xxx.xxx (xxx.xxx是文件名) 那么就会出现相类似的信息,主要都是这些: -rw-rw-r-- 一共有10位数 其中: 最前面那个 - 代表 ...