【Uva】725-Division

news/2024/5/19 2:13:05 标签: 枚举

1、题目

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 N N, where 2 ≤ N ≤ 79 2 ≤ N ≤ 79 2N79. That is,
a b c d e f g h i j = N \frac{abcde}{fghij} = N fghijabcde=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 N 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 N N by a blank line.

Sample Input

61
62
0

Sample Output

There are no solutions for 61.

79546 / 01283 = 62
94736 / 01528 = 62

725 - Division

2、题意

输入正整数 n n n,按从小到大的顺序输出所有形如 a b c d e / f g h i j = n abcde/fghij = n abcde/fghij=n 的表达式,其中 a a a ~ j j j 恰好为数字 0 ~ 9 的一个排列(可以有前导0), 2 ≤ n ≤ 79 2 \le n \le 79 2n79

3、分析

暴力枚举,但是没有必要枚举 0 ~ 9 的所有排列,只需要枚举 f g h i j fghij fghij 就可以算出 a b c d e abcde abcde,然后判断是否所有数字的偶不相同即可。枚举量从 10! - 3628800 降低至不到1万,且当 a b c d e abcde abcde f g h i j fghij fghij 加起来超过 10 位时可以终止枚举

4、代码实现

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main() {
  int n, kase = 0;
  char buf[99];
  while(scanf("%d", &n) == 1 && n) {
    int cnt = 0;
    if(kase++) printf("\n");
    for(int fghij = 1234; ; fghij++) {
      int abcde = fghij * n;
      sprintf(buf, "%05d%05d", abcde, fghij);
      if(strlen(buf) > 10) break;
      sort(buf, buf+10);
      bool ok = true;
      for(int i = 0; i < 10; i++)
        if(buf[i] != '0' + i) ok = false;
      if(ok) {
        cnt++;
        printf("%05d / %05d = %d\n", abcde, fghij, n);
      }
    }
    if(!cnt) printf("There are no solutions for %d.\n", n);
  }
  return 0;
}

http://www.niftyadmin.cn/n/5128006.html

相关文章

postgis ST_CoverageInvalidEdges用法

官方文档 概要 geometry ST_CoverageInvalidEdges(geometry winset geom, float8 tolerance 0); 描述 一个窗口函数&#xff0c;用于检查窗口分区中的多边形是否形成有效的多边形覆盖范围。 它返回线性指示器&#xff0c;显示每个多边形中无效边&#xff08;如果有&#x…

以技术创新“谋局”,洗碗机市场的风向变了

在知乎、小红书等知识社区上&#xff0c;时常可以看到一些有趣的“种草”帖&#xff1a;扫地机器人和洗碗机&#xff0c;被并称为“解放人类双手的家电产品”。 特别是洗碗机的话题下&#xff0c;不少对清洁、节能、烘干、容量等卖点进行详尽阐述的科普文章&#xff0c;动辄就…

傅里叶在图像中的应用FFT算法---fft实战应用案例

https://www.zhihu.com/question/20460630 电子衍射其实就是物质的实空间FFT变换后的倒易空间&#xff0c;在垂直于电子束方向的投影&#xff08;因为CCD相机捕捉到的是二维平面&#xff0c;一般宏观物质和其倒易空间是三维的&#xff09; 傅里叶变换有哪些具体的应用&#xff…

ESP32网络开发实例-HTTP-POST请求

HTTP-POST请求 文章目录 HTTP-POST请求1、HTTP POST2、软件准备3、硬件准备4、代码实现在本文中,我们将介绍如何使用 ESP32向 ThingSpeak等常用 API 发出 HTTP POST 请求。 1、HTTP POST 超文本传输协议 (HTTP) 用作服务器和客户端之间的请求-响应协议。 它使它们之间的通信顺…

Windows平台下将exe及其dll封包到新的exe

Windows平台下将exe及其dll封包到新的exe 〇、项目需求一、生成 exe二、通过 Dependencies 寻找所需dll三、将所需 dll 复制到 exe 同级目录下3.1 通过 python 脚本自动处理3.2 使用 Everthing 搜索特定dll3.3 验证 dll 是否完备 四、使用 Enigma Virtual Box 对 dll 和 exe 进…

解决node项目一个极度困难的捕获异常却无法读取异常信息的问题

这个项目是集成了第三方NeteaseCloudMusicApi项目的接口代码&#xff0c;我没有直接使用它的接口&#xff0c;因为需要再跑一个npm run开个端口&#xff0c;感觉很麻烦。 所以下定决心&#xff0c;使用拆分代码的方式&#xff0c;硬生生将这个api项目的部分api接口代码集成到了…

内存-虚拟地址到物理内存地址转换

虚拟地址的位数 [rootnew ~]# cat /proc/cpuinfo | grep virtu | tail -1 address sizes : 46 bits physical, 48 bits virtual 高性能C之虚拟内存_哔哩哔哩_bilibili 第零层&#xff0c;每一项是4KB 512个4KB是2MB&#xff0c;第一层&#xff0c;每一项是1GB 512个2MB是…

66 内网安全-域横向批量atschtasksimpacket

目录 演示案例:横向渗透明文传递at&schtasks 案例2-横向渗透明文HASH传递atexec-impacket案例3-横向渗透明文HASH传递批量利用-综合案例5-探针主机域控架构服务操作演示 传递攻击是建立在明文和hash值的一个获取基础上的攻击&#xff0c;也是在内网里面常见协议的攻击&…