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 ...
随机推荐
- 20160808_卸载OpenJDK
1.查看信息 [root@localhost ~]# rpm -qa | grep jdkjava-1.6.0-openjdk-devel-1.6.0.0-1.50.1.11.5.el6_3.x86_ ...
- php 新特性
PHP 5.6 1.可以使用表达式定义常量 https://php.net/manual/zh/migration56.new-features.php 在之前的 PHP 版本中,必须使用静态值来定义 ...
- Falcon:三代reads比对组装工具箱
主页:github: PacificBiosciences/FALCON 简介 Falcon是一组通过快速比对长reads,从而来consensus和组装的工具. Falcon工具包是一组简单的代码集 ...
- VB6 GDI+ 入门教程[7] Graphics 其他内容
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[7] Graphics 其他内容 2009 年 9 月 ...
- jsp页面 直接从地址栏中 获取 参数的方法
function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +"=([^&am ...
- 基于SourceTree 下的 Git Flow 模型
基于SourceTree 下的 Git Flow 模型 1. sourceTree 是一个开源的git 图形管理工具,可下载mac版本,windows版本 2. Git Flow 是一套使用Git进 ...
- OneProxy wiki上线了
文档的敏捷开发方式,希望把文档做好. http://www.onexsoft.com/dokuwiki/doku.php?id=oneproxy
- bzoj题解汇总(1017-1020)
bzoj1017: 树形dp. 设\(f[i][j][k]\)表示当前在点\(i\),有\(j\)个用于上层合成,花费金币为\(k\)的最大攻击力. bzoj1018: 一题多解. http://ww ...
- jmeter笔记1
使用 JMeter 分布式性能测试 作为一个纯 JAVA 的GUI应用,JMeter 对于CPU和内存的消耗还是很惊人的, 所以当需要模拟数以千计的并发用户时,使用单台机器模拟所有的并发用 ...
- Qt之窗口动画(下坠、抖动、透明度)
简述 前面几节中我们介绍了关于动画的基本使用,有属性动画.串行动画组.并行动画组.这节我们来实现一些特效,让交互更顺畅. 简述 示例 效果 源码 更多参考 示例 下面,我们以geometry.pos. ...