当前位置:网站首页>1996. number of weak characters in the game
1996. number of weak characters in the game
2022-07-05 05:42:00 【A big pigeon】
topic : Roles have two properties , Attack and defense . When the character's attack and defense are strictly smaller than that of a certain character , Then the role is “ Weak role ”. In the array “ Weak role ” Number .
Explain : This problem can sort the array by attack , Then compare defense . Remember that the current biggest defensive role is q, The currently accessed role is p.
If q defense >p defense , And q attack >p attack , that p Namely “ Weak role ”.
One problem is , How to ensure q defense > p Defensive time ,q attack also > p attack ?
The method given in the solution , Sort by attack descending , Attack at the same time , In ascending defense order .
It can be proved to the contrary :
hypothesis : If q Defense ratio p Big , And q Attack and p The attack is the same .
from ” Attack at the same time , In ascending defense order “ You know q It must be p Back .
But when we traverse from front to back q It must be p front , Wrong assumption .
class Solution:
def numberOfWeakCharacters(self, properties: List[List[int]]) -> int:
properties.sort(key=lambda x: (-x[0], x[1])) # Attack descending , Defense ascending
ans = 0
maxDef = 0
for _, def_ in properties:
if maxDef > def_:
ans += 1
else:
maxDef = max(maxDef, def_)
return ans
边栏推荐
- Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
- Summary of Haut OJ 2021 freshman week
- PC寄存器
- [jailhouse article] look mum, no VM exits
- Talking about JVM (frequent interview)
- kubeadm系列-00-overview
- 中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
- Hang wait lock vs spin lock (where both are used)
- AtCoder Grand Contest 013 E - Placing Squares
- Configuration and startup of kubedm series-02-kubelet
猜你喜欢
[practical skills] how to do a good job in technical training?
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
Implement a fixed capacity stack
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
Sword finger offer 05 Replace spaces
用STM32点个灯
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
shared_ Repeated release heap object of PTR hidden danger
Sword finger offer 58 - ii Rotate string left
Typical use cases for knapsacks, queues, and stacks
随机推荐
MySQL数据库(一)
Demonstration of using Solon auth authentication framework (simpler authentication framework)
Solution to game 10 of the personal field
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
ssh免密登录设置及使用脚本进行ssh登录并执行指令
【Jailhouse 文章】Performance measurements for hypervisors on embedded ARM processors
Full Permutation Code (recursive writing)
2020ccpc Qinhuangdao J - Kingdom's power
挂起等待锁 vs 自旋锁(两者的使用场合)
Gbase database helps the development of digital finance in the Bay Area
Introduction to convolutional neural network
【Jailhouse 文章】Jailhouse Hypervisor
全排列的代码 (递归写法)
Mysql database (I)
shared_ Repeated release heap object of PTR hidden danger
Zzulioj 1673: b: clever characters???
CF1637E Best Pair
SAP method of modifying system table data
A new micro ORM open source framework
sync.Mutex源码解读