LeetCode 825 適齡的朋友

2022-08-02 07:45:09 字數 937 閱讀 9438

看完條件一晃眼...好像叫德摩根定律? (似乎是離散數學裡的)

反正展開就對了

為了表達方便修改了運算子

!( b<=0.5*a+7 || b>a || (b>100 && a<100)) 

= !(b<=0.5*a+7) && !(b>a) || !(b>100 && a<100)

= b>0.5*a+7 && b<=a && (b<=100 || a>=100)

= b>0.5*a+7 && b<=a

b ∈ (14, +∞)

a ∈ [b, 2b-14)

此時直接套二分搜尋就差不多了。至於還能用計數優化什麼的就不搞了(懶

from typing import list

import bisect

class solution:

def numfriendrequests(self, ages: list[int]) -> int:

ages = sorted([x for x in filter(lambda x: x>14, ages)])

opt = 0

lastv, lasts = -1, -1

for i, v in enumerate(ages):

if v == lastv:

opt += lasts

continue

if i+1 == len(ages):

continue

lastv, lasts = v, 0

ed = bisect.bisect_left(ages, 2*v - 14, i)

if ed:

lasts = ed - i - 1

opt += lasts

return opt

8 2 5 例項分析

下面對以上 作簡要說明 1 按照常規步驟建立並拷貝 matrix rect 的matrx var mymatrix matrix matrix rect.transform.matrix 此處應該注意大小寫,transform 內部並不存在 matrix 物件。matrix 是矩陣類的名字,matr...

82 5 監控程序

列出某個程式程序所開啟的檔案資訊,顯示httpd程序現在開啟的檔案 lsof c httpd顯示多個程序命令用法 root netkiller lsof c smbd command pid user fd type device size off node name smbd 2506 root ...

CV大神講座感悟8 25

部落格做筆記,可以以後來翻看。這樣就留下了自己學習的記錄了,可能剛開始很簡單但是慢慢來逐漸積累自己的。遇到乙個問題怎麼解決 看書遇到問題就上網搜,谷歌 大神只是看書來培養起來。建議先看西瓜書,然後再看統計學習方法。實在看不懂,就看網路的 建議使用linux系統 資料收集的學習 網路選擇,是手機移動端...