当前位置:网站首页>"Problem solution" with score
"Problem solution" with score
2022-07-24 08:20:00 【Beiqi kylin】
( Math teacher : Is this the simplest score for you !)
Link to the original title :link
This is a deep search , The average time 3000 m s 3000\mathrm{ms} 3000ms; Personal practice is violence enumeration , when 139 m s 139\mathrm{ms} 139ms.
But I don't know this classmate ( metamorphosis ) 130 m s 130\mathrm{ms} 130ms How to do it ……

「 My question making process 」:
step1: Observation surface .
「 With points , Numbers 1 ∼ 9 1\sim 9 1∼9 Appears separately and only once ( It doesn't contain 0 0 0), Output the number N N N Use digital 1 ∼ 9 1\sim 9 1∼9 No repetition, no omission To form with fractions All species 」, The first thing that pops up is deep search , But because I can't figure out how to search , Turn to violence .( Question type :DFS or Violence enumeration )
step2: Think about the solution .
Grasp With the characteristics of fractional composition : Integers + False score , namely x = a + b c ( a , b , c ≠ 0 ) x = a + {b\over c}\ (a,b, c \ne 0) x=a+cb (a,b,c=0)( False fractions can be reduced to integers , namely The numerator can divide the denominator ( b = k c , c ∣ b ) (b = kc,\ c\mid b) (b=kc, c∣b) ).
So I thought of enumerating the previous integers first a a a, Then we get the result of pseudo fractional reduction k k k, By enumeration c c c To get b b b. To determine a , b , c a,b,c a,b,c Whether it meets the meaning of the question .
You can't enumerate indefinitely , Come on Estimated range . The smallest molecule is 1 1 1, Then the integer part is at least 2 2 2, The maximum denominator is 9876543 9876543 9876543, You can also get the equivalent number N N N Greater than 9876545 9876545 9876545 There is no solution to time ( However N ≤ 1 0 6 N \le 10^6 N≤106 , This N N N The scope of is useless ).
step3: Completion code .
Code ( Resist academic misconduct , Refuse Ctrl + C):#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, sum;
bool vis[11]; // Used to judge whether the number is repeated 、 missing
inline bool nosame(int x) {
// Judge whether the number of a number is repeated
memset(vis, 0, sizeof vis);
while (x != 0) {
if (vis[x % 10] || x % 10 == 0) {
return false;
}
vis[x % 10] = true;
x /= 10;
}
return true;
}
inline int len(int x) {
// Get the number of digits ( length )
int l = 0;
while (x != 0) {
l++;
x /= 10;
}
return l;
}
inline bool nopublic(int a, int b, int c) {
// Judge whether there is a duplicate number in the band score
memset(vis, 0, sizeof vis);
while (a != 0) {
vis[a % 10] = true;
if (a % 10 == 0) {
return false;
}
a /= 10;
}
while (b != 0) {
if (vis[b % 10] || b % 10 == 0) {
return false;
}
vis[b % 10] = true;
b /= 10;
}
while (c != 0) {
if (vis[c % 10] || c % 10 == 0) {
return false;
}
vis[c % 10] = true;
c /= 10;
}
return true;
}
inline void get(int x) {
int l = len(n - x);
// Enumerating multiples
for (int i = 1; i <= 9876543; i++) {
// The molecule is at least one , The integer part can only be two , The maximum denominator is 9876543
if (nosame(x * i) && nosame(i) && nopublic(x * i, i, n - x) && len(x * i) + len(i) + l == 9) {
printf("%d=%d+%d/%d\n", n, n - x, x * i, i);
sum++;
}
if (len(x * i) + len(i) + l > 9) {
// If the number is greater than 9 You don't have to count any more
break;
}
}
return;
}
int main() {
freopen("fraction.in", "r", stdin);
freopen("fraction.out", "w", stdout);
while (~scanf("%d", &n)) {
sum = 0;
for (int i = 1; i < n; i++) {
if (nosame(i)) {
get(n - i);
}
}
printf("%d\n", sum);
}
return 0;
}
data Hack What about it ~ Yours Accepted By Hack Did you drop it ~( ̄y▽, ̄)╭
Let's solve it 『 With fractions 』 beep ~
Bye bye!!1
边栏推荐
- [Google play access] payment server token acquisition
- QT | string generation QR code function
- Dynamic programming & backtracking various deformation problems
- 45. Jumping game II
- [shutter] the shutter doctor reports an error
- mysql使用explain分析sql执行计划帮助查找性能瓶颈
- Uva572 oil deposits problem solution
- jmeter中JSON提取器使用
- DGL库中一些函数或者方法的介绍
- [wechat applet development] (I) development environment and applet official account application
猜你喜欢

FPGA integrated project - image edge detection system

EZDML reverse engineering import database analysis practical operation tutorial
![[Yum] configuration and use of Yum source](/img/38/16a910d9a038d513e0b0a54ba81b93.jpg)
[Yum] configuration and use of Yum source
![[wechat applet development] (I) development environment and applet official account application](/img/94/b93d5fb6d9e3515a1f218cc4ec6eef.png)
[wechat applet development] (I) development environment and applet official account application

About the big hole of wechat applet promise
![[ByteDance] ByteDance access (including login and payment)](/img/41/700944d445f6cce5097c0c8a06a180.png)
[ByteDance] ByteDance access (including login and payment)

Vscode code style notes (vetur)

Why is knowledge base important? This is the best answer I've ever heard

What is NFT? An article to understand the concept of NFT

图新地球:如何导入修改了高程基准(椭球)的CAD文件
随机推荐
[matlab] (III) application of MATLAB in Higher Mathematics
how to add square on screenshot
[wechat applet development] (I) development environment and applet official account application
[wechat applet development] (II) wechat native bottom tabbar configuration
赛宁TechTalk丨攻防演练:攻击组合拳 “稳准狠”渗透
[ByteDance] ByteDance access (including login and payment)
栈/堆/队列刷题(下)
Assembly | screen display numbers
News topic classification task -- tochtext library for text classification
Dynamic programming & backtracking various deformation problems
Hegong sky team vision training day4 - traditional vision, contour recognition
Figure New Earth: how the RVT format BIM model modeled by Revit can accurately match the map with texture
P1739 expression bracket matching problem solution
mysql使用explain分析sql执行计划帮助查找性能瓶颈
SOA and microservice examples
Installation and use of CONDA
55. Jumping game
[redis] how much do you know about bloom filter and cuckoo filter?
Brief notes on the key points of distributed system principle introduction
【MATLAB】(三)MATLAB在高等数学中的应用