UVa 725 Division (枚举)
题意 : 输入正整数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 (枚举)的更多相关文章
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(除法)暴力法!
uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- uva 725 DIVISION (暴力枚举)
我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...
- UVa 725 简单枚举+整数转换为字符串
Division Write a program that finds and displays all pairs of 5-digit numbers that between them use ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
- UVA 725 – Division
Description Write a program that finds and displays all pairs of 5-digit numbers that between them ...
随机推荐
- centos7部署rabbitMq
目录 一.消息中间件相关知识... 1 1.概述... 1 2.消息中间件的组成... 1 3 消息中间件模式分类... 2 4 消息中间件的优势... 3 5 消息中间件应用场景... 4 6 消息 ...
- [转帖]站点部署,IIS配置优化指南
站点部署,IIS配置优化指南 https://www.cnblogs.com/heyuquan/p/deploy-iis-set-performance-guide.html 挺值得学习的 毕竟之前很 ...
- Spring(三)--Spring bean的生命周期
Spring bean的生命周期 ApplicationContext Bean生命周期流程 1.需要的实体类 ackage com.xdf.bean; import org.springframew ...
- Laravel5.8自定义函数存放位置
1. 创建文件 app/helpers.php <?php // 示例函数 function foo() { return "foo"; } 2. 修改项目 composer ...
- python日记:优化(SEO)狗学Python的日子(1)
一名优秀的程序员,在穿越单行道时也会确认双向的来车情况 ——道格拉斯.林德(Doug Linder) 大家可能好奇Python是什么东东,今天是小猿开始学习Python的第一天.周五在公司的时候收到了 ...
- python基础预习小结
一.执行python程序的两种方式 1.1 交互式 在终端内输入python3,然后输入python代码 1.2 命令式 在终端内输入python3文本文件路径 二.执行python的两种IDE 2. ...
- 在Vue项目中加载krpano全景图
在Vue-cli项目中做krpano全景图编辑器的时候,由于js插件的路径是动态的,做的过程中遇到了加载不到资源的难题,在网上搜索了好久也没找到合适的办法,最后想到了可能是JS加载的问题,于是解决了问 ...
- mybatis 插入数据返回 -1
通常使用mybatis对数据进行增删改会进行返回值的判断, 返回值不为1时说明该条语句执行失败,不过今天遇到程序报错返回值不为1,去数据库查看却发现插入成功了,后来知道原来是因为mybatis一次对多 ...
- MySQL基础入门之常用命令介绍
mysql命令介绍 mysql 是数据库管理命令 通过mysql --help来查看相关参数及使用说明 mysql --help #mysql数据库管理命令 Usage: ...
- 传输层协议之TCP/UDP
1.UDP UDP协议是面向无连接的,即不需要在正式传递数据前先链接双方,UDP协议只是数据报文的搬运工,不保证有序且不丢失的传递到对端,且UDP协议无任何控制流量的算法,UDP相对于TCP更加轻便. ...