当前位置:网站首页>Niuke real problem programming - day16
Niuke real problem programming - day16
2022-07-07 14:53:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Compile environment :c++
1、 Shanzhai glitters
describe :
After Jin Shanshan died , red A Got the treasure of the king , There are n A weapon , The lengths are different . red A Find out , Take three of these weapons head to tail , Form a triangle , Perform the calling ceremony , You can summon a Shanzhai Jinshan .( for example , The length of three weapons is 10、15、20, Can summon success . If the length is 10、11、30, The triangle cannot be formed by connecting the head and the tail , Call failed .) red A So he opened a glittering store . He lined up the treasures of the king , Each guest will be randomly selected into an interval [l,r], Guests can choose three weapons in the section to summon ( The guests are very intelligent , If you can find the right weapon , I will never let go ). After the call , Guests should put the weapons back as they are .m After a guest patronized , red A Afraid of too much glitter, happy too many men , So I found you , I hope you can help him count how many Shanzhai Jinshan were summoned .
Data range : 1≤n≤10^7 , 1≤m≤10^6 , The length of each weapon meets 1≤val<2^32
Algorithmic thought :
Declare array first , Store the length of each weapon entered . We can go until : For a given three numbers , In ascending order , If the sum of the smallest two numbers is greater than the third number , Then it must form a triangle . Therefore, it is necessary to judge whether a triangle call can be formed in the interval , Then the elements in the interval can be arranged in ascending order , Work in groups of three to judge whether the conditions are met .
To optimize code efficiency . Because the length of each weapon is 2^32 within a country's boundaries , Also known , For a given ascending sequence , If you want to be unable to form a triangle , It can only be arranged like Fibonacci sequence :1、1、2、3、5..... because 2^32-1=4294967295, In the Fibonacci sequence 47,48 position 2971215073,4807526976 Between . So there are conditions when the interval is greater than 46 There is no need to make complex algorithm judgment , It must form a triangle ( Weapons are different , therefore 1、2 Bit 1 Drop one ).
The code part implements :

2、 Phone number separation
describe :
Following MIUI8 After launching the mobile phone separation function ,MIUI9 Plan to launch a phone number separation function : First, add... To each number in the phone number 8 Take a place , Then use the corresponding capital letter instead of ("ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"), Then randomly shuffle the letters , The generated string is the corresponding part of the phone number .
Algorithmic thought :
First, record the number of various letters in the input string , With automatic conversion ascii Code as an index of letters . It is difficult to recover a complete numeric string from a scrambled string , So we can observe the characters unique to each numeric character , First , The five easiest to distinguish are FOUR(U),SIX(X),TWO(W),EIGHT(G),ZERO(Z), You can directly judge how many corresponding numbers there are according to the number of these special letters ; Then exclude all the letters they contain , Then other numbers with repeated letters have special letters , Yes FIVE(F),THREE(T); After excluding the number of letters contained in these numbers , And then there is SEVEN Contains special V,; In the end ONE(O),NINE(I).
Then push back +8 Previous figures , Such as now 4 The number of corresponds to the original phone number 6 The number of . Then store 0-9 The smallest phone number combination can be obtained by sequentially outputting an array of numbers .
The code part implements :

3、 At the end of 0 The number of
describe :
Enter a positive integer n, seek n!( That is factorial ) How many at the end 0? such as : n = 10; n! = 3628800, So the answer is 2
Algorithmic thought :
0 The last bit of is actually 5 Multiplied by an even number , Then we can decompose n Factorial of all numbers , Find one of them 2 and 5 The number of . And because the number of even numbers is far greater than 5 The number of , So we can directly consider n How many factorials can be decomposed 5 that will do .n/5 It is the closest n The factorial of an integer of contains 5 The number of , such as 20/5=4,20 There is 5,10,15,20 four 5 Multiple . Then continue to recursively call the result , such as 125 The factorial of contains 25,25 Can be decomposed into 2 individual 5... Print the results
The code part implements :

边栏推荐
- Xiaomi's path of chip self-development
- WebRTC 音频抗弱网技术(上)
- FFmpeg----图片处理
- Instructions for mictr01 tester vibrating string acquisition module development kit
- 用于增强压缩视频质量的可变形卷积密集网络
- Attribute keywords serveronly, sqlcolumnnumber, sqlcomputecode, sqlcomputed
- 寺岗电子称修改IP简易步骤
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验12 RTC实时时钟实验(学习笔记)
- 6. Electron borderless window and transparent window lock mode setting window icon
- 拜拜了,大厂!今天我就要去厂里
猜你喜欢

"July 2022" Wukong editor update record

【历史上的今天】7 月 7 日:C# 发布;Chrome OS 问世;《仙剑奇侠传》发行

Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System

Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."

Leetcode one question per day (636. exclusive time of functions)

Zhiting doesn't use home assistant to connect Xiaomi smart home to homekit

AWS learning notes (III)

Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System

leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】

Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)
随机推荐
Huawei cloud database DDS products are deeply enabled
Mlgo: Google AI releases industrial compiler optimized machine learning framework
The method of parsing PHP to jump out of the loop and the difference between continue, break and exit
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条...
2022云顾问技术系列之高可用专场分享会
因员工将密码设为“123456”,AMD 被盗 450Gb 数据?
Small game design framework
Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
Summary on adding content of background dynamic template builder usage
Promoted to P8 successfully in the first half of the year, and bought a villa!
Deformable convolutional dense network for enhancing compressed video quality
时空可变形卷积用于压缩视频质量增强(STDF)
Lidar knowledge drops
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
一文读懂数仓中的pg_stat
Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)
leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
Read PG in data warehouse in one article_ stat
Stm32cubemx, 68 sets of components, following 10 open source protocols
一文读懂数仓中的pg_stat