当前位置:网站首页>Niuke real problem programming - Day17
Niuke real problem programming - Day17
2022-07-07 14:53:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Compile environment :c++
1、 Shooting game
describe :
There is a shooting game . The court has p A basket , The number is 0,1...,p-1. There is a bag under each basket , Each bag can hold at most one basketball . Yes n A basketball , Each ball number xi . The rule is to set the number to xi Our basketball shot xi except p The remainder of is in the numbered bag . If there is basketball in the bag, the ball pops up and the game ends i, Otherwise repeat until all shots are thrown . Output -1. Ask what the final output of the game is ?
Algorithmic thought :
The topic idea is actually very simple , Just simulate the whole process , And the title doesn't seem to explain the number of the ball i It's from 1 At the beginning , Attention should be paid to when outputting results . my bug It's typing n When the ball hits , Input and processing are put together , It took a long time to debug at the beginning , Because the game may end when processing , But the input of the use case is not completely over , Resulting in the following result error . Finally, I chose to separate two cycles , The value of each input ball is summed , The number of balls accumulating the same remainder , When the number is no longer 1 when , You can interrupt the game . If it ends naturally , You can declare an extra bool Quantity to determine whether output -1 identification .

2、 Minimum quantity of goods packed
describe :
The weights are 3,5,7 Three kinds of goods in kilograms , And a payload of X Kilogram boxes ( Regardless of volume and other factors , Only calculate the weight )
Need to fill the box X Kilogram cargo , It is required to use as few goods as possible ( The quantity of three kinds of goods is unlimited )
Data range : 1≤x≤10000
Algorithmic thought :
The problem is actually a knapsack problem of dynamic programming . set up dp[i] by i The minimum number of goods per kilogram , that dp[i] It must be equal to i-3,i-5,i-7 The minimum quantity of three kilograms +1 Minimum of , Then we can get the recurrence equation of dynamic programming , namely dp[i] = min(min(dp[i-3],dp[i-5]),dp[i-7])+1. First of all to dp3、5、6、7 The initialization , Then call recursive .
The code part implements :

3、 Go up the steps
describe :
There is a staircase for m level , At first you were at the first level , If you can only step up one or two levels at a time , To go on m level , How many ways are there ? notes : It is stipulated that from level one to level one there are 0 Seed walking method .
Given a positive integer int n, Please return a number , Number of ways to go upstairs . Guarantee n Less than or equal to 100. To prevent spillage , Please return the result Mod 1000000007 Value .
Algorithmic thought :
This problem is also dynamic programming . set up dp[i] by i The number of steps , Decomposition subproblems have m The steps can only be taken from m-1/m-2 Step up , Because I can only walk every time 1/2 Steps . So we can get the recursion of this problem dp[i]=(dp[i-1]+dp[i-2]). Remember to initialize dp[1]、2、3 Initial value of , And consider the problem of data overflow .
The code part implements :

边栏推荐
- 华为云数据库DDS产品深度赋能
- Used by Jetson AgX Orin canfd
- Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
- Mlgo: Google AI releases industrial compiler optimized machine learning framework
- CPU与chiplet技术杂谈
- CTFshow,信息搜集:web1
- Attribute keywords ondelete, private, readonly, required
- 半小时『直播连麦搭建』动手实战,大学生技术岗位简历加分项get!
- 拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条...
- EMQX 5.0 发布:单集群支持 1 亿 MQTT 连接的开源物联网消息服务器
猜你喜欢

Simple use of websocket

Pytorch model trains practical skills and breaks through the bottleneck of speed

「2022年7月」WuKong编辑器更版记录

15、文本编辑工具VIM使用

Niuke real problem programming - day15

Promoted to P8 successfully in the first half of the year, and bought a villa!

Niuke real problem programming - day13

Niuke real problem programming - Day9
![[Yugong series] go teaching course 005 variables in July 2022](/img/66/4265a06a98412bd2c88d8281caf06e.png)
[Yugong series] go teaching course 005 variables in July 2022

What is cloud primordial? This time, I can finally understand!
随机推荐
Summary on adding content of background dynamic template builder usage
Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
《微信小程序-进阶篇》组件封装-Icon组件的实现(一)
在软件工程领域,搞科研的这十年!
PyTorch模型训练实战技巧,突破速度瓶颈
The method of parsing PHP to jump out of the loop and the difference between continue, break and exit
Substance painter notes: settings for multi display and multi-resolution displays
PG basics -- Logical Structure Management (locking mechanism -- table lock)
Protection strategy of server area based on Firewall
Attribute keywords ondelete, private, readonly, required
JS in the browser Base64, URL, blob mutual conversion
Niuke real problem programming - day13
Deformable convolutional dense network for enhancing compressed video quality
PAG experience: complete AE dynamic deployment and launch all platforms in ten minutes!
Base64 encoding
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
Ffmpeg --- image processing
asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design
13 ux/ui/ue best creative inspiration websites in 2022
leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】