当前位置:网站首页>[exercise-6] (UVA 725) division = = violence
[exercise-6] (UVA 725) division = = violence
2022-07-06 15:56:00 【Flame car】
translate :
Enter a positive integer n, Output all shapes from small to large, such as abcde/fghij=n The expression of , among a~j Exactly a number 0 ~9 An arrangement of ( There can be leads 0),2≤n≤79
This question is not difficult , I think it's interesting , So write casually .
AC Code :
#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++)// Count
num[x1%10]++,num[x2%10]++,x1/=10,x2/=10;
for(int i=0;i<=9;i++)// Judge whether it is a 0~9 An arrangement of
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;
}
}
So why is it written like this ? First, let's write the formula in this form A / B = C, Then it can be simplified into ,A = B * C. and C We know this time , As long as we enumerate B That is, the denominator , Also can put the A Show it .
So the idea is very clear , enumeration B( One ), And then use B Multiply what you already know C, obtain A( Two ). Judge A and B Is it right? 0~9 Just sort all the numbers !
The judgment is simple. Just make a cycle , And we know B * C That is to say A It can't be greater than 98765 Of , This can also be used as a termination condition .
边栏推荐
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
- C语言是低级和高级的分水岭
- C语言必背代码大全
- 通俗地理解什么是编程语言
- Opencv learning log 30 -- histogram equalization
- Web based photo digital printing website
- VS2019初步使用
- TCP的三次握手与四次挥手
- C语言数组的概念
猜你喜欢

【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)

Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
![[exercise-7] crossover answers](/img/66/3dcba2e70a4cd899fbd78ce4d5bea2.png)
[exercise-7] crossover answers

C语言数组的概念

Penetration test (3) -- Metasploit framework (MSF)

X-forwarded-for details, how to get the client IP

D - Function(HDU - 6546)女生赛

Penetration test (1) -- necessary tools, navigation

【练习-5】(Uva 839)Not so Mobile(天平)

入门C语言基础问答
随机推荐
对iptables进行常规操作
Accounting regulations and professional ethics [3]
Cost accounting [13]
X-forwarded-for details, how to get the client IP
Opencv learning log 33 Gaussian mean filtering
想应聘程序员,您的简历就该这样写【精华总结】
程序员的你,有哪些炫技的代码写法?
渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
China's PCB connector market trend report, technological innovation and market forecast
Opencv learning log 19 skin grinding
MATLAB综合练习:信号与系统中的应用
TCP的三次握手与四次挥手
Cost accounting [22]
Gartner: five suggestions on best practices for zero trust network access
信息安全-威胁检测引擎-常见规则引擎底座性能比较
【练习-3】(Uva 442)Matrix Chain Multiplication(矩阵链乘)
STM32 how to use stlink download program: light LED running light (Library version)
CS zero foundation introductory learning record
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
【高老师UML软件建模基础】20级云班课习题答案合集