当前位置:网站首页>【练习-6】(Uva 725)Division(除法)== 暴力
【练习-6】(Uva 725)Division(除法)== 暴力
2022-07-06 09:26:00 【火焰车】
翻译:
输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰好为数字0 ~9的一个排列(可以有前导0),2≤n≤79
这道题不难,觉得挺有意思的,所以随便写写。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll mod = 1e9+7;
int num[20];
bool solve(int x1,int x2){
memset(num,0,sizeof num);
if(x2>98765)
return 0;
for(int i=0;i<5;i++)//取数
num[x1%10]++,num[x2%10]++,x1/=10,x2/=10;
for(int i=0;i<=9;i++)//判断是不是一个0~9的一个排列
if(num[i]!=1)
return 0;
return 1;
}
int main()
{
int n,cnt=0;
while(cin>>n && n)
{
int flag = 1;
for(int i=1234;i<=98765;i++)
{
if(solve(i,i*n))
{
flag = 0;
printf("%05d / %05d = %d\n",n*i,i,n);
}
}
if(flag)
printf("There are no solutions for %d.\n",n);
cout<<endl;
}
}
那么为什么这么写?首先我们把式子形式写成这样 A / B = C,然后就可以化简成了,A = B * C。而且C我们是已知这个时候,只要我们枚举B也就是分母,也可以把A给表示出来了。
所以思路就很清楚了,枚举B(一个),然后用B乘已经知道的C,得到A(两个)。判断A和B是不是0~9所有数字的排序就可以了!
判断简单啊做个循环就行了,而且我们知道B * C也就是A是不可能大于98765的,这样也可以作为一个终止条件。
边栏推荐
- Learning record: understand systick system timer and write delay function
- Cost accounting [14]
- 信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
- Cost accounting [22]
- STM32 learning record: LED light flashes (register version)
- ucore lab 6
- Opencv learning log 30 -- histogram equalization
- Alice and Bob (2021牛客暑期多校训练营1)
- Opencv learning log 18 Canny operator
- JS --- detailed explanation of JS DOM (IV)
猜你喜欢
STM32 learning record: play with keys to control buzzer and led
Determine the Photo Position
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
C语言数组的概念
JS --- all basic knowledge of JS (I)
入门C语言基础问答
STM32 learning record: input capture application
学习记录:TIM—基本定时器
Learning record: how to perform PWM output
MATLAB实例:阶跃函数的两种表达方式
随机推荐
Determine the Photo Position
Record of brushing questions with force deduction -- complete knapsack problem (I)
Ball Dropping
ucore lab7
D - Function(HDU - 6546)女生赛
TCP的三次握手与四次挥手
Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
Opencv learning log 19 skin grinding
C语言必背代码大全
Opencv learning log 16 paperclip count
Opencv learning log 15 count the number of solder joints and output
通俗地理解什么是编程语言
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
想应聘程序员,您的简历就该这样写【精华总结】
Opencv learning log 33 Gaussian mean filtering
C 基本语法
JS --- BOM details of JS (V)
Cost accounting [19]
基于web的照片数码冲印网站
0 - 1 problème de sac à dos (1)