当前位置:网站首页>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
边栏推荐
- 【Jailhouse 文章】Jailhouse Hypervisor
- 26、 File system API (device sharing between applications; directory and file API)
- EOJ 2021.10 E. XOR tree
- Acwing 4301. Truncated sequence
- CF1634E Fair Share
- 卷积神经网络简介
- Haut OJ 1401: praise energy
- kubeadm系列-00-overview
- Software test -- 0 sequence
- kubeadm系列-01-preflight究竟有多少check
猜你喜欢
剑指 Offer 05. 替换空格
Introduction and experience of wazuh open source host security solution
用STM32点个灯
shared_ Repeated release heap object of PTR hidden danger
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
【实战技能】如何做好技术培训?
Personal developed penetration testing tool Satania v1.2 update
Full Permutation Code (recursive writing)
从Dijkstra的图灵奖演讲论科技创业者特点
浅谈JVM(面试常考)
随机推荐
Typical use cases for knapsacks, queues, and stacks
Introduction to memory layout of FVP and Juno platforms
Hang wait lock vs spin lock (where both are used)
2022年贵州省职业院校技能大赛中职组网络安全赛项规程
Introduction et expérience de wazuh open source host Security Solution
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
A new micro ORM open source framework
API related to TCP connection
Add level control and logger level control of Solon logging plug-in
过拟合与正则化
Acwing 4300. Two operations
F - Two Exam(AtCoder Beginner Contest 238)
【Jailhouse 文章】Jailhouse Hypervisor
Simply sort out the types of sockets
[practical skills] how to do a good job in technical training?
个人开发的渗透测试工具Satania v1.2更新
Over fitting and regularization
Codeforces Round #715 (Div. 2) D. Binary Literature
The number of enclaves