首页 > 其他分享 >1386. Cinema Seat Allocation

1386. Cinema Seat Allocation

时间:2022-12-27 18:22:25浏览次数:44  
标签:index four seat Seat Allocation seats 1386 reservedSeats row

img

A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.

Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already reserved.

Return the maximum number of four-person groups you can assign on the cinema seats. A four-person group occupies four adjacent seats in one single row. Seats across an aisle (such as [3,3] and [3,4]) are not considered to be adjacent, but there is an exceptional case on which an aisle split a four-person group, in that case, the aisle split a four-person group in the middle, which means to have two people on each side.

Example 1:
123

Input: n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]
Output: 4
Explanation: The figure above shows the optimal allocation for four groups, where seats mark with blue are already reserved and contiguous seats mark with orange are for one group.
Example 2:

Input: n = 2, reservedSeats = [[2,1],[1,8],[2,6]]
Output: 2
Example 3:

Input: n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]
Output: 4

Constraints:

1 <= n <= 10^9
1 <= reservedSeats.length <= min(10*n, 10^4)
reservedSeats[i].length == 2
1 <= reservedSeats[i][0] <= n
1 <= reservedSeats[i][1] <= 10
All reservedSeats[i] are distinct.

class Solution:
    def maxNumberOfFamilies(self, n, reservedSeats):
        res = 0
        reservedSeats.sort()
        index = 0
        row_count = 0
        while index < len(reservedSeats):
            row = reservedSeats[index][0]
            flag1, flag2, flag3 = 1, 1, 1
            while index < len(reservedSeats) and reservedSeats[index][0] == row:
                seat = reservedSeats[index][1]
                if seat in [2, 3, 4, 5]:
                    flag1 = 0
                if seat in [6, 7, 8, 9]:
                    flag3 = 0
                if seat in [4, 5, 6, 7]:
                    flag2 = 0
                index += 1
            if flag1 and flag3:
                res += 2
            elif flag1 or flag2 or flag3:
                res += 1
            row_count += 1
        return res + (n - row_count) * 2

标签:index,four,seat,Seat,Allocation,seats,1386,reservedSeats,row
From: https://www.cnblogs.com/bernieloveslife/p/17008703.html

相关文章

  • Seata-php 入门与下半年展望
    通俗地讲,Seata-php是seata的PHP语言实现,实现了Java和PHP之间的互通,让PHPer也能使用seata-php来实现分布式事务。Seata是一个非常成熟的分布式事务框架,在Java......
  • 微服务系列:分布式事务 Spring Cloud Alibaba 之 Seata 实战篇
    ​​微服务系列:分布式事务SpringCloudAlibaba之Seata入门篇​​在上一篇入门篇中,我们已经对​​Seata​​​有了大致的了解,并搭建好了​​seata-server​​​服务......
  • Spring Cloud - Seata
    分布式事务:第一阶段要做的事情:1. 开启全局事务,获取全局事务id;2. 执行业务逻辑,生成前置镜像、后置镜像,插入undo_log,执行本地事务;3. 在插入undo_log之前,会发起一个rpc请求......
  • MIT 6.828 Homework: Xv6 lazy page allocation
    PartOne:Eliminateallocationfromsbrk()任务将sbrk(n)系统调用实现中的分配page部分删除,在sysproc.c中的sys_sbrk()中。在删除之后,新的sbrk(n)应该仅仅将......
  • Seata
      Seata事务ID的传递https://www.cnblogs.com/ciel717/p/16185061.html发送:SeataFeignClient替换了默认的feignClient,把xid放到了requestHeader里。SeataFeig......
  • 如何参与开源贡献—SeaTunnel为例 文2
    如何参与开源贡献—SeaTunnel为例文2创建issue5.3.1什么是issue每个github的仓库下都会有一个项目独立的issue板块。在这个板块里面,大家可以提出自己的问题,也可以去和大......
  • 如何参与开源贡献—SeaTunnel为例 文1
    如何参与开源贡献—SeaTunnel为例文15.1基本概念5.1.1参与开源贡献的常见方法1)参与解答在社区中,帮助使用过程中遇到困难的人,帮他们解释框架的用法也算是一种贡献。2)文档......
  • SeaTunnel入门教程
    SeaTunnel教程第1章Seatunnel概述1.1SeaTunnel是什么SeaTunnel是一个简单易用的数据集成框架,在企业中,由于开发时间或开发部门不通用,往往有多个异构的、运行在不同的软硬......
  • Centos7下Seata的安装和配置
    Seata是由阿里中间件团队发起的开源项目Fescar,后更名为Seata,它是一个是开源的分布式事务框架。传统2PC的问题在Seata中得到了解决,它通过对本地关系数据库的分支事务的协调......
  • 全网首发:Seata Saga状态机设计器实战
    前言目前业界公认Saga是作为长事务的解决方案。而seata作为目前最流行的分布式事物解决方案也提供了Saga的支持。而采用Seata的Saga模式进行事物控制,核心就是通过状态机来......