题目描述:

自己的提交:

# """
# This is Sea's API interface.
# You should not implement it, or speculate about its implementation
# """
#class Sea(object):
# def hasShips(self, topRight: 'Point', bottomLeft: 'Point') -> bool:
#
#class Point(object):
# def __init__(self, x: int, y: int):
# self.x = x
# self.y = y class Solution(object):
def countShips(self, sea: 'Sea', topRight: 'Point', bottomLeft: 'Point') -> int:
if topRight.x == bottomLeft.x and topRight.y == bottomLeft.y and sea.hasShips(topRight,bottomLeft):
return 1
if sea.hasShips(topRight,bottomLeft):
mid_h = (topRight.y + bottomLeft.y)//2
mid_w = (topRight.x + bottomLeft.x)//2
a = self.countShips(sea,Point(mid_w,topRight.y),Point(bottomLeft.x,mid_h+1)) if mid_h != topRight.y else 0
b = self.countShips(sea,topRight,Point(mid_w+1,mid_h+1)) if mid_h != topRight.y and mid_w != topRight.x else 0
c = self.countShips(sea,Point(mid_w,mid_h),bottomLeft)
d = self.countShips(sea,Point(topRight.x,mid_h),Point(mid_w+1,bottomLeft.y)) if mid_w != topRight.x else 0
return a + b + c + d
return 0

leetcode-第14周双周赛-1274-矩形内船只的数目的更多相关文章

  1. LeetCode 第 14 场双周赛

    基础的 api 还是不够熟悉啊 5112. 十六进制魔术数字 class Solution { public: char *lltoa(long long num, char *str, int ra ...

  2. LeetCode第8场双周赛(Java)

    这次我只做对一题. 原因是题目返回值类型有误,写的是 String[] ,实际上应该返回 List<String> . 好吧,只能自认倒霉.就当涨涨经验. 5068. 前后拼接 解题思路 ...

  3. Java实现 LeetCode第30场双周赛 (题号5177,5445,5446,5447)

    这套题不算难,但是因为是昨天晚上太晚了,好久没有大晚上写过代码了,有点不适应,今天上午一看还是挺简单的 5177. 转变日期格式   给你一个字符串 date ,它的格式为 Day Month Yea ...

  4. LeetCode 第 15 场双周赛

    1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...

  5. leetcode-第14周双周赛-1273-删除树节点

    题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...

  6. leetcode-第14周双周赛-1272-删除区间

    题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[ ...

  7. leetcode-第14周双周赛-1271-十六进制魔术数字

    自己的提交: class Solution: def toHexspeak(self, num: str) -> str: num = hex(int(num)) num = str(num)[ ...

  8. leetcode-第12周双周赛-5111-分享巧克力

    题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible( ...

  9. leetcode-12周双周赛-5090-抛掷硬币

    题目描述: 二维dp: class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float ...

随机推荐

  1. 解决如何通过循环来使用数据库的值设置jsp的select标签的option值

    Select 处的代码: <select name="position"> <span style="white-space:pre"> ...

  2. Python函数中*args和**kwargs来传递变长参数的用法

    参考自: http://www.jb51.net/article/78705.htm 单星号形式(*args)用来传递非命名键可变参数列表.双星号形式(**kwargs)用来传递键值可变参数列表. 1 ...

  3. 【MySQL】实现自增函数sequence

    前言 当前数据库为:mysql由于mysql和oracle不太一样,不支持直接的sequence,所以需要创建一张table来模拟sequence的功能,理由sql语句如下: 步骤 1.创建seque ...

  4. [BZOJ3379] Turning in Homework

    中文题目:提交作业 原文题目:Turning in Homework 传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3379 哎,今天竟然没有 ...

  5. [CSP-S模拟测试]:math(裴蜀定理)

    题目传送门(内部题22) 输入格式 第一行有$2$个整数$n,k$.第二行有$n$个正整数$a_i$. 输出格式 第一行有一个整数$s$,表示可以生成的非负整数的个数.第二行有$s$个可以生成的非负整 ...

  6. SQL学习记录:定义(一)

    --1.在这里@temp是一个表变量,只有一个批处理中有效,declare @temp table; --2. 如果前面加#就是临时表,可以在tempDB中查看到,它会在最后一个使用它的用户退出后才失 ...

  7. C#链接mysql出现 One of the identified items was in an invalid format

    这个问题在tolist查询结果的时候就会出现但是count就不会出现,后来才发现是数据生成工具生成出来的ID有问题导致的,只要保证iD不重复并且按照指定的类型建立ID就可以了

  8. 公司-IT-SanSan:SanSan

    ylbtech-公司-IT-SanSan:SanSan 毫不费力的组织.无缝简单.基于名片的联系人管理 SanSan是一个名片管理应用,为企业提供内部联系人管理和分享服务,此外该公司也是日本最大的.基 ...

  9. CentOS7下python虚拟环境

    搭建python虚拟环境 1.我们先创建一个隐藏目录 .virtualenvs,所有的虚拟环境都放在此目录下 :mkdir /root/.virtualenvs 2.安装虚拟环境 确认pip:wher ...

  10. kubernetes原理

    kubernetes 核心组件 etcd:保存整个集群的状态 apiserver:提供资源操作的唯一入口,并提供认证.授权.访问控制.api注册和发现等机制 controller manager:负责 ...