题意 : 输入正整数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. 【Qt开发】Qt5.7串口开发

    QT5有专门的串口类:  QSerialPort:提供访问串口的功能  QSerialPortInfo:提供系统中存在的串口的信息  具体使用方法:  1.在pro文件中加入: QT += seria ...

  2. flask config笔记

    #从flask这个包中导入Flask这个类 #Flask这个类是项目的核心,以后很多操作都是基于这个类的对象 #注册url.注册蓝图等都是基于这个类的对象 from flask import Flas ...

  3. java.math包简介

    java.math包提供了java中的数学类 包括基本的浮点库.复杂运算以及任意精度的数据运算   '可以看得到,主要包括三个类一个枚举 BigDecimal和BigInteger接下来会详细介绍 先 ...

  4. java期末考试

    水仙花数 package txt; public class shuixianhua { public static void main(String[] args) { // TODO Auto-g ...

  5. Luogu P2839 [国家集训队]middle

    题目 首先我们考虑解决中位数一类问题的常用手段:二分\(mid\),将大于等于它的设为\(1\),小于它的设为\(−1\),判断区间和是否\(\ge0\). 对于询问\(a,b,c,d\),二分完\( ...

  6. ftp读取图片并转Base64

    public String download(String ftpUrl,String sfzh){ FTPClient ftpClient = new FTPClient(); InputStrea ...

  7. PythonDay09

    第九章函数 今日内容 函数定义 函数调用 函数返回值 函数的参数 函数定义 # 通过定义一个计算数据长度的函数,def为关键字,count_len是函数名def count_len(): lst = ...

  8. sqlalchemy query函数可用参数有哪些?

    一.模型名 二.模型对象属性 三.聚合函数 下面就分别为大家讲讲query函数这三种参数的用法. 在讲之前,我已经把数据库连接配置.模型,以及添加数据写好了,代码如下: from sqlalchemy ...

  9. 一道并发和锁的golang面试题

    今天面试golang碰到了一道考并发和锁的题目,没有完成,所以把它记录下来,仅为以后复习. 场景:在一个高并发的web服务器中,要限制IP的频繁访问.现模拟100个IP同时并发访问服务器,每个IP要重 ...

  10. LeetCode 338. 比特位计数

    338. 比特位计数 题目描述 给定一个非负整数 num.对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回. 示例 示例 1: 输入: 2 输出 ...