Program A - 暴力求解
Description
Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where 2<=N<=79. That is,
abcde / fghij =N
where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.
Input
Each line of the input file consists of a valid integer N. An input of zero is to terminate the program.
Output
Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator).
Your output should be in the following general form:
xxxxx / xxxxx =N
xxxxx / xxxxx =N
.
.
In case there are no pairs of numerals satisfying the condition, you must write ``There are no solutions for N.". Separate the output for two different values of N by a blank line.
Sample Input
61
62
0
Sample Output
There are no solutions for 61. 79546 / 01283 = 62
94736 / 01528 = 62 分析:如果将abcde与fghij都枚举出来会超时,所以只枚举fghij再用N乘以它就可以得到abcde,在判断a-j中各个数字都不同就可以了。
#include <iostream>
#include <cstdio>
using namespace std;
int used[10];
int image(int x,int y)
{
if(y>98765)
return 0;
for(int i=0;i<10;i++)
used[i]=0;
if(x<10000)
used[0]=1;
while(x)
{
used[x%10]=1;
x/=10;
}
while(y)
{
used[y%10]=1;
y/=10;
}
int sum=0;
for(int i=0;i<10;i++)
sum+=used[i];
return (sum==10); }
int main()
{
int n,t=0;
while(scanf("%d",&n)==1&&n)
{
int flag=0;
if(t++)
printf("\n");
for(int i=1234;i<100000;i++)
{
if(image(i,i*n))
{
printf("%05d / %05d = %d\n",i*n,i,n);
flag=1; }
}
if(!flag)
printf("There are no solutions for %d.\n",n);
}
}
Program A - 暴力求解的更多相关文章
- Program C 暴力求解
Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...
- Program L 暴力求解
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- Program B 暴力求解
Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maxim ...
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~
jrMz and angle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu6570Wave (暴力求解)
Problem Description Avin is studying series. A series is called "wave" if the following co ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
随机推荐
- 值类型,引用类型,栈,堆,ref,out
在网上收集... C#的值类型,引用类型,栈,堆,ref,out C# 的类型系统可分为两种类型,一是值类型,一是引用类型,这个每个C#程序员都了解.还有托管堆,栈,ref,out等等概念也是每个C# ...
- HBase的shell命令行界面按退格键(Backspace)无法删除问题
在HBase的shell命令行界面输入错误项按"退格键"删除,却怎么也删除不了: 解决办法: 第一步,修改SecureCRT的设置参数: 第二步,按"Ctrl+退格键(B ...
- Axure_元件库
1.百度“推荐”,看到一篇文章“用Axure制作Material Design的APP原型(附元件库下载)” 想到 可以搜索 类似“axure 元件库”的关键字,来看看有哪些现成的元件库 2.
- (转)ConcurrentHashMap解析
原文地址:http://www.ibm.com/developerworks/cn/java/java-lo-concurrenthashmap/ ConcurrentHashMap 的结构分析 为了 ...
- 项目框架开发流程(oa项目为例)
1. 导包 2. 配置web.xml 3. 设计通用dao ,base,service, action, domain ,utils等 4.配置struts.xml 和 beans.xml 5. 配 ...
- iOS设置app应用程序文件共享
1.iOSapp应用程序文件共享 当我们用itnues连接到设备时,在应用程序栏目下面,文件共享下,点击 对应的程序,即可以在程序右边栏目里面看到应用程序共享的数据, 此时,我们可以通过右下角的 添加 ...
- 串行通讯之UARTLoopback
目录 第1章串行通讯之UARTLoopback 2 1 USB转串口 2 2 USB Accessory 2 3 连入手机 3 4 代码改进 4 5 打开串口 4 ...
- js用ajax和不同页面的php互相传值的方法
js里的代码:<script> var json; //获取所有class名为zhi的标签 var zhi = document.getElementsByClassName('zhi') ...
- DSP基础学习-ADC同步采样
DSP基础学习-ADC同步采样 彭会锋 2015-04-28 20:31:06 在DSP28027 LauchPad学习过程中,关于ADC同步采样和顺序采样的区别稍加研究了一下,发现里面还真有些门道, ...
- java SE学习之线程同步(详细介绍)
java程序中可以允许存在多个线程,但在处理多线程问题时,必须注意这样一个问题: 当两个或多个线程同时访问同一个变量,并且一些线程需要修改这个变量时,那么这个 ...