【Leetcode】1386. Cinema Seat Allocation
题目地址:
https://leetcode.com/problems/cinema-seat-allocation/description/
电影院有 n n n行,每行 10 10 10个位置,给定若干已经占据的位置,问能安排多少个 4 4 4人组,每个组占据 2345 , 4567 , 6789 2345,4567, 6789 2345,4567,6789之一。
先用位运算表示一下有占据位置的行的情况,然后分情况讨论来累加,最后加上 2 2 2乘以空行的数量。代码如下:
class Solution {public:int maxNumberOfFamilies(int n, vector<vector<int>>& v) {unordered_map<int, int> mp;for (auto& e : v) mp[e[0]] |= 1 << e[1] - 1;int res = 0;const int full = (1 << 4) - 1;for (auto& [k, x] : mp) {if (!(x >> 1 & full) && !(x >> 5 & full))res += 2;else if (!(x >> 1 & full) || !(x >> 3 & full) || !(x >> 5 & full))res++;}res += 2 * (n - mp.size());return res;}
};
时空复杂度 O ( l v ) O(l_v) O(lv)。
【Leetcode】1386. Cinema Seat Allocation相关推荐
- 【LeetCode】849. Maximize Distance to Closest Person
[LeetCode]849. Maximize Distance to Closest Person 849. Maximize Distance to Closest Person Easy In ...
- 【LeetCode】849. Maximize Distance to Closest Person 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode】100. 相同的树
题目 给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 1: 输入: 1 1/ \ / \2 3 2 3[1,2,3], [1 ...
- 【leetcode】85. Maximal Rectangle 0/1矩阵的最大全1子矩阵
1. 题目 Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...
- 【leetcode】486. Predict the Winner
题目如下: Given an array of scores that are non-negative integers. Player 1 picks one of the numbers fro ...
- 【leetcode】132. Palindrome Partitioning II
题目如下: 解题思路:本题是[leetcode]131. Palindrome Partitioning的升级版,要求的是求出最小cuts,如果用[leetcode]131. Palindrome P ...
- 【leetcode】86. Partition List
题目如下: Given a linked list and a value x, partition it such that all nodes less than x come before no ...
- 【Leetcode】103. 二叉树的锯齿形层次遍历
题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 ...
- 【Leetcode】79.单词搜索
题目 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻"单元格是那些水平相邻或垂直相邻的单元格.同一个单元格 ...
最新文章
- 如何直观地理解「协方差矩阵」?
- 微信小程序学习做动画效果
- Java总复习(一)
- linux常用shell命令之目录操作命令
- 如何查看ubuntu的版本信息和查看几位 32 or 64位
- python回归模型 变量筛选_如何进行高维变量筛选和特征选择(一)?Lasso回归
- 大叔手记(21):汤姆大叔博客园开博100天总结
- 最好用的手机端C/C++语言编程软件, 不要说没电脑就不学编程了!
- 使用docker连接远程仓库反复出现密码错误
- 小企业电脑如何组网_(完整版)中小型企业组网方案
- Java SE 第二十三讲----static关键字and final关键字
- HDU - 3506 Monkey Party
- 中调用view_在 View 上使用挂起函数
- 广州大彩串口屏与STM32F407通讯
- 【渝粤教育】电大中专消费者行为学_1作业 题库
- 作业二:wireshark抓包与ping操作
- 国开教育学形考任务2试题1试题及答案
- 自考行政管理题库(含答案)
- HTML5期末大作业:动漫人物介绍网站设计——柯南(5页) HTML+CSS+JavaScript 学生DW网页设计作业成品 学生动漫网页设计模板下载
- VSCode-解决更新代码时报would clobber existing tag