题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a~j恰好为数字0~9的一个排列(可以有前导0),2≤n≤79。

分析 : 最暴力的方法莫过于采用数组存储0~9然后next_permutation枚举排列再带入表达式看是否满足等式,但是这样的复杂度就是O(10!)了,时间复杂度超高。所以采取另外一种枚举方法,先枚举分母fghij,再根据分母算出分子,然后检测分母分子出现的字数是否有重复即可。那这样的复杂度是多少呢?复杂度主要就在枚举分母上了,枚举分母的方法就是采用一个for(int Flood=1234; Flood<100000; Flood++); ,枚举量大大减少。

O(10!)

#include<bits/stdc++.h>
using namespace std;

int main(void)
{
    int n;
    ] = {,,,,,,,,,};
    ;
    while(~scanf("%d", &n) && n){
        if(blank++) puts("");
        bool Have = false;
        do{
            ]* + digit[]* + digit[]* + digit[]* + digit[];
            ]* + digit[]* + digit[]* + digit[]* + digit[];
            ],digit[],digit[],digit[],digit[],digit[],digit[],digit[],digit[],digit[],n);Have=true;}
        }));
        if(!Have) printf("There are no solutions for %d.\n", n);
    }
    ;
}

O(AC)

#include<bits/stdc++.h>
using namespace std;
bool check(int Ceil, int Flood)
{
    ];
    ; i<; i++) digit[i] = false;
    ) digit[] = true;
    while(Ceil){
        ;
        if(digit[remainder]) return false;
        else digit[remainder] = true;
        Ceil/=;
    }
    ){
        ]) return false;
        ] = true;
    }
    while(Flood){
        ;
        if(digit[remainder]) return false;
        else digit[remainder] = true;
        Flood/=;
    }
    return true;
}
int main(void)
{
    int n;
    ;
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    while(~scanf("%d", &n) && n){
        if(blank++) puts("");
        bool Have = false;
        ; Flood<; Flood++){
            int Ceil = Flood * n;
            ) continue;
            else{
                if(check(Ceil, Flood)){
                    Have = true;
                    ) putchar(');
                    printf("%d / ", Ceil);
                    ) putchar(');
                    printf("%d = %d\n", Flood, n);
                }
            }
        }
        if(!Have) printf("There are no solutions for %d.\n", n);
    }
    ;
}

UVa 725 Division (枚举)的更多相关文章

  1. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

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

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

  3. UVA.725 Division (暴力)

    UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...

  4. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  5. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  6. uva 725 DIVISION (暴力枚举)

    我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...

  7. UVa 725 简单枚举+整数转换为字符串

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

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

  9. UVA 725 – Division

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

随机推荐

  1. vue父子组件相互传值的实例

    当子组件需要向父组件传递数据时,就要用到自定义事件 子组件用 $emit()来触发事件,父组件用$on()来监昕子组件的事件 父组件也可以直接在子组件的自定义标签上使用 v-on 来监昕子组件触发的自 ...

  2. windows jenkins 发布 springboot项目脚本

    windows  jenkins 发布 springboot项目脚本 1.关闭现有程序 (按端口关闭) [与按应用关闭 二选一] @echo off for /f "tokens=1-5&q ...

  3. 并发之AQS原理(二) CLH队列与Node解析

    并发之AQS原理(二) CLH队列与Node解析 1.CLH队列与Node节点 就像通常医院看病排队一样,医生一次能看的病人数量有限,那么超出医生看病速度之外的病人就要排队. 一条队列是队列中每一个人 ...

  4. win10+vs2013+pcl1.8.0(x86) 环境配置遇到的各种小问题解决

    1.PCL提供了各自的PDB调试文件(解压后放入pcl安装目录的bin下) 2.OpenNI的安装需同其余在pcl第三方库文件夹下 3.添加附加依赖项的.lib文件请按照网上对应版本添加,另外需要每行 ...

  5. Windows7下Pycharm安装Keras

    1.安装Anaconda3 2.安装Pycharm 3.安装TensorFlow 一.File -> Settings -> Install 二.搜索TensorFlow -> In ...

  6. ActionsChains类鼠标事件和Keys类键盘事件

    一.鼠标事件 如,移动.点击.释放.单击.右击,拖动等 键盘事件如:输入.回车.粘贴.复制.剪贴等 使用ActionsChains类和Keys类之前都必须先导入       from selenium ...

  7. $NOI$ $2019$ 网络同步赛

    D2T1考试前测了自己造的“假”极限数据,看了看内存发现是118MB,感觉没问题就交上去了. 赛后用Lemon测了一下:MLE 88->0 对于别的题我已经不想再说什么了. update: 由于 ...

  8. Gym 101466(完整)

    题目链接 :点击此处 ## Problem A 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 题解: 字典树.我们首先将前i-1为放入字典树中,然后在查询第 ...

  9. Kibana多用户创建及角色权限控制

    1 介绍 ELK日志管理属于基础设施平台,接入多个应用系统是正常现象,如果接入多个系统的索引文件没有进行权限划分,那么很大程度会出现索引文件误处理现象,为了避免这种情况发生,多用户及权限设置必不可少. ...

  10. Python 经典面试题(一)

    一.浮点数运算 题目 判断浮点数的运行结果是否相等:  a = 0.1 b = 0.2 c = 0.3 assert a + b == c 题目解析: 本题考查的是计算机的浮点运算知识点.不仅是 py ...