dongshuang0011 2019-05-29 20:33
浏览 75

预订系统:根据访客数量查找房间组合 - PHP

I am preparing a booking system and solving a specific problem. I have the following data structure (room number/occupancy/ price):

$room[222][1] = 80;

$room[223][1] = 100; //Room ID 222, occupancy 1 guest, price €100
$room[223][2] = 200; //Room ID 222, occupancy 2 guest, price €200
$room[223][3] = 300; //...

$room[224][1] = 110;
$room[224][2] = 220;
$room[224][3] = 330;
...

I need to find the best (lowest price) combination of rooms for a specified number of guests.

For example: For the 4 guests is the best combination of room $room[222][1] and room $room[223][3]. The total price of the rooms is €380.

Can you help me?

  • 写回答

1条回答 默认 最新

  • dqf35839 2019-05-29 21:03
    关注

    First, I would make the rooms a more descriptive object so something like this: Second, I wouldn't store price per customer like that, rather focus on capacity and go from there

      $room = array();
      $room[222] = array(
        'capactiy' => '3',
        'price' => array(
          1 => '100', //Use a string, likely you'll have .99 or whatever
          2 => '200',
          3 => '300',
        ),
        'booked' => false,
      );
    

    So you have 3 customers come in: Loop through available rooms, if the amount of people is less than capacity then cool, book it, else (say capacity is 2) then remove 2 from the amount of customers needing room, Then loop again and grab the next room

    If you want to get complex, say they want to be right next to each other, take room 222 + 1, is it available? if no then 223 + 1, is it available? yes? great! book it.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题