如何用c / c ++解决这个飞机座位问题 [英] How do I solve this airplane seating problem in c/c++

查看:152
本文介绍了如何用c / c ++解决这个飞机座位问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

航空公司有几架相同类型的飞机。每架飞机的座位数为24 X 3排,每排8个座位分开显示。



An airlines company has several planes of the same type.Each plane has a seating capacity of 24 X 3 rows and 8 seats in each row split has shown.

1 [a] [b] [c] [d] [e] [f] [g] [h]
2 [a] [b] [c] [d] [e] [f] [g] [h]
3 [a] [b] [c] [d] [e] [f] [g] [h]





如果4人预订 - 在中间行分配4个座位。右边2个,左边2个。



如果3人预订 - 身份中间部分为空,请继续分配。请转到下一行中间部分。



如果2人预订 - 分配边缘座位。



如果有1人预订 - 然后分配任何可用的免费座位。



例如 -

输入4

输出-1c 1d 1e 1f



输入-3

输出 - 2c 2d 2e



输入-2

输出-1a 1b



这是在接受采访时向我询问的。我的逻辑并不适用于所有情况。任何帮助将不胜感激。



If 4 people book - allocate 4 seats in middle row.Else 2 on the right and 2 on the left.

if 3 people book - id middle section is empty,allocate there continuously.Else go to next row middle section.

if 2 people book - allocate the edge seats.

if 1 person has booked - then allocate whatever free seat available.

eg-
input 4
output-1c 1d 1e 1f

input-3
output- 2c 2d 2e

input-2
output-1a 1b

This was asked to me in an interview. My logic doesn't work for all cases. Any help would be appreciated.

推荐答案

看起来并不困难:要求已经定义了算法(使用独立的分配策略)。

在每次输入时,根据乘客人数,您只需考虑可用座位即可找到第一个合适的位置。你有什么疑问?
It doesn't look that difficult: The requirements already define the algorithm (that uses independent allocation strategies).
At each input, based on the number of passengers, you just have to find the first fit, considering only available seats. What is your doubt about?


这篇关于如何用c / c ++解决这个飞机座位问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆