当前位置:网站首页>[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 .
边栏推荐
- Accounting regulations and professional ethics [4]
- China potato slicer market trend report, technical dynamic innovation and market forecast
- 毕业才知道IT专业大学生毕业前必做的1010件事
- MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
- Opencv learning log 32 edge extraction
- C 基本语法
- cs零基础入门学习记录
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- 【高老师UML软件建模基础】20级云班课习题答案合集
- Information security - threat detection - detailed design of NAT log access threat detection platform
猜你喜欢
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
Nodejs+vue online fresh flower shop sales information system express+mysql
【高老师软件需求分析】20级云班课习题答案合集
Penetration test (7) -- vulnerability scanning tool Nessus
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
C语言是低级和高级的分水岭
程序员的你,有哪些炫技的代码写法?
VS2019初步使用
【高老师UML软件建模基础】20级云班课习题答案合集
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
随机推荐
China potato slicer market trend report, technical dynamic innovation and market forecast
Research Report on market supply and demand and strategy of China's land incineration plant industry
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
【练习-5】(Uva 839)Not so Mobile(天平)
动态规划前路径问题优化方式
China's earthwork tire market trend report, technical dynamic innovation and market forecast
China earth moving machinery market trend report, technical dynamic innovation and market forecast
最全编程语言在线 API 文档
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
Nodejs+vue online fresh flower shop sales information system express+mysql
Opencv learning log 32 edge extraction
Path problem before dynamic planning
Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
Cost accounting [13]
Learning records: serial communication and solutions to errors encountered
Perinatal Software Industry Research Report - market status analysis and development prospect forecast
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
Penetration test (7) -- vulnerability scanning tool Nessus
Record of brushing questions with force deduction -- complete knapsack problem (I)
China's earthwork equipment market trend report, technical dynamic innovation and market forecast