UVA 725 Division(除法)
输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰好为数字0~9的一个排列,2n79。
题解:暴力破解枚举fghij。
#include<iostream>
#include <string>
#include <string.h>
#include<vector>
#include<stack>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<iomanip>
using namespace std;
const int maxn = 50000;
int main()
{
int kase=0;int a[5], b[5];int x = 0; while (cin >> x && x) {if(kase)cout<<endl;kase++;int c = 99999 / x; bool iscout = false;for (int i = 1234; i <= c; i++) {int k = i;for (int z = 0; z < 5; z++) {a[z] = k % 10; k /= 10;}bool isequal = false;for (int z = 0; z < 5; z++) {for (int j = z + 1; j < 5; j++) {if (a[z] == a[j]) {isequal = true; break;}}}if (isequal)continue;int to = i * x;if (to >= 100000)break;int tx = to;for (int z = 0; z < 5; z++) {b[z] = tx % 10; tx /= 10;}isequal = false;for (int z = 0; z < 5; z++) {for (int j = z + 1; j < 5; j++) {for (int r = 0; r < 5; r++)if (b[z] == a[r] || b[j] == a[r]) {isequal = true; break;}if (b[z] == b[j]) {isequal = true; break;}}}if (isequal)continue;/*cout << to << " / " << right << setw(5) << setfill('0') << i << " = " << x << endl;*/printf("%05d / %05d = %d\n", to, i, x);iscout = true;}if (!iscout)printf("There are no solutions for %d.\n", x);}//system("pause");return 0;
}
UVA 725 Division(除法)相关推荐
- 暴力枚举 UVA 725 Division
题目传送门 1 /* 2 暴力:对于每一个数都判断,是否数字全都使用过一遍 3 */ 4 #include <cstdio> 5 #include <iostream> 6 # ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA 725 Divisions 除法(暴力,0 ms)
本题较为简单,将不会编写算法分析说明与代码编写指导. AC 代码(0 ms): #include<cstdio> #include<cstdlib> #include<c ...
- 22行代码AC——例题7-1除法(Division UVa 725)——解题报告
励志用尽量少的代码做高效的表达 题目(提交)链接→UVa-725 题目大意: 0-9不重复的组成两个5位数,如果数A/数B=n,则为可行解. 思路分析: 本题实质是通过巧妙分析的暴力求解法. 下等解法 ...
- Uva 725 除法
紫书P182 直接枚举 0~9 的全排列会超时,枚举fghij就可以了,计算出 abcde ,这里有一个新的函数,也可以不用咯,把每一位数据提取出来,while循环可以做到,这里的新的函数是,spri ...
- 725 - Division
Division Write a program that finds and displays all pairs of 5-digit numbers that between them use ...
- UVA - 725 Division-sprintf的妙用
题目: 输入整数n,按从小到大顺序输出所有形如abcde/fghij=n的表达式,其中a~j 恰好为0~9的一个排列(可以有前导0),2<=n<=79 解题思路: 暴力枚举. 下面这代码暴 ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
- 算法竞赛入门经典 第七章 总结
目录: 7.1 简单枚举 7.2 枚举排列 7.3 子集生成 7.1 简单枚举 例题7-1 除法(Division, UVa 725) 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij ...
最新文章
- 西门子smart200以太网通讯协议
- Webpack 的简单介绍
- 写得蛮好的linux学习笔记(二)
- P1091 合唱队形[单调性+DP]
- python面试总结
- Word2016此功能看似已中断...
- Unity DF-GUI 中文输入以及自动换行
- 解决数据库报唯一性约束错误的实践
- 和电商有关的词语_电商描写的词语 形容“电”的词语有哪些?
- vue加跨域代理静态文件404_解决vue-router history模式和跨域代理 部署到IIS时404的一些问题...
- scrapy中自定义过滤规则以及start_urls不进过滤器的问题
- .ashx文件与.ashx.cs
- LayaAir TTF字体使用
- 公路自行车入门级推荐java_开学季:9款值得买公路车推荐
- Python基础语法1 —— 变量、数据类型
- Django创建APP
- php mysql 柱状图,使用EChat通过php连接mysql数据库从而实现将数据转换为柱状图
- Android混淆、反编译基础教程
- matlab的循环结构
- C++学习笔记(五)opencv在win下的使用 —参考浅墨opencv3编程入门