当前位置:网站首页>Step num problem
Step num problem
2022-07-25 20:32:00 【Xiao Lu wants to brush the questions】
List of articles
subject
Define what is step sum?
such as 680,680 + 68 + 6 = 754,680 Of step sum It's called 754
Give a positive number num, Judge whether it is a certain number step sum
Their thinking

a number X Its steps and are called a , a number Y Its steps and are called B .
First of all, I have a corollary , If Y>X, Its steps and B can only be greater than a .
Two points
If the sum of steps in the middle is less than the target , It's in 1-mid Two points in
If the sum of the two halves of the middle is greater than the target , It's in mid+1-target Do two points
If you lose two points , I didn't get it either 7268, Illustrate this 7268 Not any number of steps and
This ideological tradition comes from a noun called monotony , Just rely on monotony , It gives you a little bit of monotony sensitivity
Code
public static boolean isStepSum(int stepSum) {
int L = 0;
int R = stepSum;
int M = 0;
int cur = 0;
while (L <= R) {
M = L + ((R - L) >> 1);
cur = stepSum(M);
if (cur == stepSum) {
return true;
} else if (cur < stepSum) {
L = M + 1;
} else {
R = M - 1;
}
}
return false;
}
public static int stepSum(int num) {
int sum = 0;
while (num != 0) {
sum += num;
num /= 10;
}
return sum;
}
summary
We first use the tabulation method to find out if X Greater than Y, be X The steps and of are also greater than Y And this conclusion
With this conclusion , We found the monotonicity , We can use two points
边栏推荐
- Behind every piece of information you collect, you can't live without TA
- MySQL 日期【加号/+】条件筛选问题
- Link list of sword finger offer question bank summary (III) (C language version)
- Socket error Event: 32 Error: 10053. Connection closing...Socket close
- Cloud native guide: what is cloud native infrastructure
- Chapter VI modified specification (SPEC) class
- Docker builds redis cluster
- PMP practice once a day | don't get lost in the exam -7.25
- [advanced mathematics] [6] differential calculus of multivariate functions
- 智能电子界桩自然保护区远程监控解决方案
猜你喜欢

JVM(二十三) -- JVM运行时参数

MySQL 日期【加号/+】条件筛选问题

【高等数学】【3】微分中值定理与导数的应用

When AI encounters life and health, Huawei cloud builds three bridges for them

「分享」DevExpress ASP.NET v22.1最新版本系统环境配置要求
![[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now

【高等数学】【1】函数、极限、连续

Interpretation of filter execution sequence source code in sprigboot

Docker builds redis cluster

Learn FPGA from the bottom structure (16) -- customization and testing of pll/mmcm IP
随机推荐
QQ是32位还是64位软件(在哪看电脑是32位还是64位)
Redis source code -ziplist
Log in to Baidu online disk with cookies (websites use cookies)
Online random coin tossing positive and negative statistical tool
Three skills of interface request merging, and the performance is directly exploded!
Card link
The database empties the table data and makes the primary key start from 1
C language file reading and writing
103. (cesium chapter) cesium honeycomb diagram (square)
Leetcode customs clearance: hash table six, this is really a little simple
【高等数学】【6】多元函数微分学
【NOI模拟赛】字符串匹配(后缀自动机SAM,莫队,分块)
process.env
2022.7.24-----leetcode.1184
Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!
Network protocol: TCP part2
[noi simulation] string matching (suffix automata Sam, Mo team, block)
Docker builds redis cluster
[onnx] export pytorch model to onnx format: support multi parameter and dynamic input
Behind every piece of information you collect, you can't live without TA