当前位置:网站首页>The problem of finding three color flags in C language test 165
The problem of finding three color flags in C language test 165
2022-06-09 22:18:00 【Maserati】
Personal home page : Personal home page
Series column :C Language test questions 200 example
Recommend a brush algorithm 、 written examination 、 Face the 、 Nada Corporation offer Artifact Click jump to enter the website
Author's brief introduction : Hello everyone , I'm Maserati ,CSDN Blogger ( Ranking of the whole station Top 50), Alibaba cloud blog expert 、51CTO Blogger 、 Huawei cloud sharing expert
1、 subject
subject : There's a rope , There's red on it 、 white 、 Flags in three colors of blue . The colors of the flags on the rope are out of order , Now we have to classify the flags , According to blue 、 white 、 In red order . You can only move on the rope , And only two flags can be exchanged at a time , How to move the flag so that it can be moved at least ?:
analysis :
The flag moves on the rope , And only two flags can be exchanged at a time , So just make sure that when you move the flag , Start at the beginning of the rope , The blue flag moves forward , The white flag is left in the middle , The red flag moves backwards . To minimize the number of moves , You can use three pointers b、w、r As blue flag 、 White and red flags .
if w The current flag pointed by the pointer is white , be w The pointer increases 1, It means adding one side to the white flag . if w The current flag pointed by the pointer is blue , Will b The pointer and w The flags pointed to by the pointer are exchanged , meanwhile b The pointer and w The pointer increases 1, It means that both the blue flag and the white flag have an element . if w The pointer points to
边栏推荐
- The 14th Sudoku - true standard Sudoku -day 6-20220121 (supplementary)
- 购买内存条前的行动
- Slightly more complex queries
- BLE链路层空中包格式
- 在 4GB 物理內存的機器上,申請 8G 內存會怎麼樣?
- Chez scheme environment setup
- IAR打开工程编译未响应、卡死 & STM32CubeMX生成工程时出错
- Spider PI intelligent vision hexapod robot automatic obstacle avoidance 0604
- 2022安全生产月活动启动安全生产与疫情防控两手抓
- 继承的所有特征
猜你喜欢

Cookie 和 Session 工作流程

Spider PI intelligent vision hexapod robot tag recognition apirltag tag 0604

Light detection and ranging (LIDAR)

Sqlserver2012 does not allow to modify the table structure 0607

TL,你是如何管理项目风险的?

【首发】根据壁纸修改App主题,它真的来了

原型对象的应用 给数组对象强化功能 0526

稍微复杂的查询

数据库每日一题---第7天:订单最多的客户

datagridview的基本使用 0526
随机推荐
The application of prototype object strengthens the function of array object 0526
函数对象(仿函数)
C语言试题162之圆周率π
Début de la production de sécurité et prévention et contrôle des épidémies
Spider PI intelligent vision hexapod robot color tracking face recognition 0604
Basic use of WinForm programming control treeview tree view 20220527
Light Detection and Ranging (LiDAR)光探测和测距 (LiDAR)
为什么健身?
npm和yarn
Bonner visual lens lcf08lk1f
体系化目标一健身合辑
How to implement a custom rich text editor label
SPIDER Pi Intelligent Vision hexapode Robot VNC Connect Robot 0603
IAR打开工程编译未响应、卡死 & STM32CubeMX生成工程时出错
尽一份孝心,为家人做一个老人防摔报警系统
Is it safe for flush to open an account? How to open an account?
RCNN系列总结
[play with Huawei cloud] initial experience of MapReduce service
继承的所有特征
BLE链路层空中包格式