当前位置:网站首页>[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 .
边栏推荐
- 信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
- Record of brushing questions with force deduction -- complete knapsack problem (I)
- Record of force deduction and question brushing
- 0-1 knapsack problem (I)
- Web based photo digital printing website
- Market trend report, technical innovation and market forecast of Chinese hospital respiratory humidification equipment
- Matlab example: two expressions of step function
- Determine the Photo Position
- 【练习-6】(PTA)分而治之
- Accounting regulations and professional ethics [2]
猜你喜欢
C语言数组的概念
毕业才知道IT专业大学生毕业前必做的1010件事
Ball Dropping
Information security - threat detection engine - common rule engine base performance comparison
Penetration test (7) -- vulnerability scanning tool Nessus
Learning record: how to perform PWM output
MATLAB综合练习:信号与系统中的应用
Gartner: five suggestions on best practices for zero trust network access
Gartner:关于零信任网络访问最佳实践的五个建议
[exercise-7] crossover answers
随机推荐
HDU-6025-Coprime Sequence(女生赛)
China's PCB connector market trend report, technological innovation and market forecast
X-Forwarded-For详解、如何获取到客户端IP
7-1 懂的都懂 (20 分)
D - Function(HDU - 6546)女生赛
Path problem before dynamic planning
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
China's earthwork equipment market trend report, technical dynamic innovation and market forecast
0-1 knapsack problem (I)
毕业才知道IT专业大学生毕业前必做的1010件事
【练习-3】(Uva 442)Matrix Chain Multiplication(矩阵链乘)
Learning record: USART serial communication
Record of brushing questions with force deduction -- complete knapsack problem (I)
Information security - threat detection engine - common rule engine base performance comparison
Essai de pénétration (1) - - outils nécessaires, navigation
Market trend report, technical innovation and market forecast of geosynthetic clay liner in China
F - Birthday Cake(山东省赛)
基于web的照片数码冲印网站
0 - 1 problème de sac à dos (1)
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools