当前位置:网站首页>Niuke real problem programming - Day10
Niuke real problem programming - Day10
2022-07-07 14:52:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Compile environment :c++
1、 Generate Gray code
describe
In the coding of a set of numbers , If any two adjacent codes have only one binary number different , This code is called gray code (Gray Code), Please write a function , Use recursive method to generate N Bit gray code .
Given an integer n, Please return n Bit gray code , The order is from 0 Start .
Algorithmic thought :
According to the characteristics of gray code , It's not hard to find out ,N Bit gray code is in N-1 Add 1 Bit 0 perhaps 1, And the number is 2 Of N individual : front 2 Of N-1 And after 2 Of N-1 The first N-1 Bit symmetry , All are N-1 Bit generated gray code , the N-1 Bit generated gray code +0/1 Output in positive and negative order . According to this design recursive function getGray, When N by 1 when , Gray code is 0 and 1. Note that the output of the topic just returns to the previous N Gray code generated by sub recursion .
The code part implements :
2、zj2 Programming questions 1
describe
There are three teams , Each team number is team 1, The team 2, The team 3, The three teams need to play a total of n game . Now it's over k game , Every game can't be tied , Win a game and get a point , If you lose, you can't lose points . Known team 1 And the team 2 There is a difference in the score between d1 branch , The team 2 And the team 3 There is a difference in the score between d2 branch , You can choose two teams to play in each game . Please, if you finish the last (n-k) game , Is it possible that the scores of the three teams are even .
Algorithmic thought :
The title just gives the difference , But there is no positive or negative difference , Therefore, it can be divided into four situations to discuss respectively . At the same time, the scores of the three teams are added =k,ab The difference is +-d1,bc The difference is +-d2 Equation thinking to divide the situation, exhaustive . When a<0,b<0,c<0;n No 3 A multiple of the , It must not meet the conditions . classification 1:a<b<c when , here a+b+c=a+(a+d1)+(a+d1+d2)=3x1+2d1+d2=k, Yes x1=(k-2*d1-d2)/3, obviously , In order to catch up, we need to meet the remaining games n-k Greater than or equal to (2*d2+d1), At the same time, the extra games should be allocated to three teams at the same time . The other three cases are the same , Press d1d2 Positive and negative classification discussion .
The code part implements :
3、DNA Sequence
describe :
Niuniu has another task from biological researchers , Niuniu needs to help scientific researchers from DNA Sequence s Find the shortest that does not appear in DNA Sequence s Medium DNA Length of segment .
for example :s = AGGTCTA
The sequence contains all elements with a length of 1 Of ('A','C','G','T') fragment , But the length is 2 Of does not contain all , For example, the sequence does not contain "AA", So the output 2.
notes : The length is 2 All DNA The clip has "AA"、"AC"、"AG"、"AT"、"CA"、"CC"、"CG"、"CT"、"GA"、"GC"、"GG"、"GT"、"TA"、"TC"、"TG" and "TT", common 16 Kind of .
Algorithmic thought :
make the best of c++ Library function , Received s After the string , From the length to 1 Start intercepting substrings , Then put it into a set , Because the element key is unique in the set , So the insert operation first checks whether the given key already exists in the collection , It's equivalent to removing weight . At this time, you only need to judge whether the number of elements in the set meets the inclusion length of i All of the DNA fragment , namely size Be greater than 4 Of i Power .
The code part implements :
边栏推荐
- 今日睡眠质量记录78分
- 属性关键字OnDelete,Private,ReadOnly,Required
- PAG体验:十分钟完成AE动效部署上线各平台!
- leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】
- 6. Electron borderless window and transparent window lock mode setting window icon
- PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
- In the field of software engineering, we have been doing scientific research for ten years!
- PAG experience: complete AE dynamic deployment and launch all platforms in ten minutes!
- Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
- Jetson AGX Orin CANFD 使用
猜你喜欢
Zhiting doesn't use home assistant to connect Xiaomi smart home to homekit
The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
2022pagc Golden Sail award | rongyun won the "outstanding product technology service provider of the year"
全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
Stm32cubemx, 68 sets of components, following 10 open source protocols
asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
【历史上的今天】7 月 7 日:C# 发布;Chrome OS 问世;《仙剑奇侠传》发行
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
WebRTC 音频抗弱网技术(上)
随机推荐
AWS学习笔记(三)
Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
解析PHP跳出循环的方法以及continue、break、exit的区别介绍
Andriod --- JetPack :LiveData setValue 和 postValue 的区别
Xiaomi's path of chip self-development
AWS learning notes (III)
Nllb-200: meta open source new model, which can translate 200 languages
用于增强压缩视频质量的可变形卷积密集网络
Mmkv use and principle
2022pagc Golden Sail award | rongyun won the "outstanding product technology service provider of the year"
半小时『直播连麦搭建』动手实战,大学生技术岗位简历加分项get!
上半年晋升 P8 成功,还买了别墅!
FFmpeg----图片处理
Full details of efficientnet model
C 6.0 language specification approved
The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
Differences between cookies and sessions
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
Delete a whole page in word
How bad can a programmer be? Nima, they are all talents