题意 : 输入正整数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. Oracle中的=:

    dept_code=:dCode =:在这里的意思是变量绑定

  2. python 并发编程 基于gevent模块 协程池 实现并发的套接字通信

    基于协程池 实现并发的套接字通信 客户端: from socket import * client = socket(AF_INET, SOCK_STREAM) client.connect(('12 ...

  3. Solrcloud+tomcat+zookeeper

    准备两台服务器,目录结构如下 主机名 IP地址 tomcat安装路径 zookeeper安装路径 solr安装路径 java安装路径 sht-sgmhadoopnn-01 172.16.101.55 ...

  4. 【五一qbxt】test1

    (不知道为什么居然爆零了qwq) (全员爆零诶,最高分10分???还是rand出来的???) 我freopen写错了????自闭了 不行不行再写一遍freopen加深印象,不能再写错了 freopen ...

  5. noip2013day2-华容道

    题目描述 小 \(B\) 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用 编程来完成华容道:给定一种局面,华容道是否根本就无法完成,如果能完成,最少需要多 少时间. 小 \(B ...

  6. C语言 --- 函数指针(初级)

    1.函数指针:指向函数的指针变量.                 函数在内存中也是有地址的,函数名代表函数的内存地址.    例子:函数:int sum(int a,int b);      int ...

  7. PythonDay14

    第十四章装饰器 装饰器 # 开放封闭原则- 1.对扩展是开放的- 2.对修改是封闭的​# 在不修改源代码和调用方式的情况下,对函数进行扩展# 第一版装饰器def times(func):    def ...

  8. Spark RDD理解-总结

    1.spark是什么 快速.通用.可扩展的分布式计算引擎. 2. 弹性分布式数据集RDD RDD(Resilient Distributed Dataset),是Spark中最基本的数据抽象结构,表示 ...

  9. python 路径操作工具 pathlib,比 os 模块好用太多

    在 python 当中,如果你想控制路径,基本上绕不开 os.path.我希望看完这篇文章以后,熟练使用 python 的你能立刻开始使用 pathlib 模块,一刻也不要耽误. pathlib 相对 ...

  10. 34、Scrapy 知识总结

      Scrapy 知识总结   1.安装   pip install wheel pip install https://download.lfd.uci.edu/pythonlibs/q5gtlas ...