题意 : 输入正整数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. netcore 实现一个简单的Grpc 服务端和客户端

    参考资料,和详细背景不做赘述. 首先定义prop 文件 syntax ="proto3"; package RouteGrpc; service HelloWorld{ rpc S ...

  2. WM_RBUTTONUP消息收不到问题

    今天遇到了个问题,对某窗口进行右键弹出菜单,发现没弹出来,然后打断点发现WM_RBUTTONUP消息收不到 捣鼓了下,找到了原因. 在Duilib中,当设置了Caption后,Duilib处理鼠标点击 ...

  3. hue的load balance

    参考: hue的load balance官网: https://www.cloudera.com/documentation/enterprise/6/6.2/topics/hue_use_add_l ...

  4. [转帖]关于Ubuntu与Debian的关系,了解!

    关于Ubuntu与Debian的关系,了解! https://blog.csdn.net/guyue35/article/details/47286193 了解一下区别..   饮水思源:Ubuntu ...

  5. mysql for update 高并发 死锁研究

    mysql for update语句     https://www.cnblogs.com/jtlgb/p/8359266.html For update带来的思考 http://www.cnblo ...

  6. Python 之父 63 岁才退休,我 23 就中年危机。。

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 Python 之父 Guido van Rossum 在推特公布了自己从 Dropbox 公司离职的消息,并表示已经退休. ...

  7. noip2013day1-货车运输

    题目描述 \(A\)国有\(n\)座城市,编号从 \(1\)到\(n\),城市之间有 \(m\) 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 \(q\) 辆货车在运输货物, 司机们想知 ...

  8. [CF750G] New Year and Binary Tree Paths

    目录 简单的 组合的 题目链接 简单的 设从节点\(x\)开始不断往左儿子走h-1步,则编号和为\(x\sum_{i=0}^{h-1}2^i=x(2^h-1)\). 若倒数第\(i\)步走向的是右儿子 ...

  9. python 链接mysql 连接池

    # python 链接mysqlimport mysql.connector.poolingconfig = { "host":"localhost", &qu ...

  10. 史上最全的大厂Mysql面试题在这里

    1.MySQL的复制原理以及流程 基本原理流程,3个线程以及之间的关联: 主:binlog线程——记录下所有改变了数据库数据的语句,放进master上的binlog中: 从:io线程——在使用star ...