当前位置:网站首页>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
边栏推荐
- Pointnet++学习
- Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
- Wazuh开源主机安全解决方案的简介与使用体验
- Brief introduction to tcp/ip protocol stack
- 软件测试 -- 0 序
- Summary of Haut OJ 2021 freshman week
- Haut OJ 2021 freshmen week II reflection summary
- Dichotomy, discretization, etc
- Simple knapsack, queue and stack with deque
- 第六章 数据流建模—课后习题
猜你喜欢
随机推荐
Gbase database helps the development of digital finance in the Bay Area
Talking about JVM (frequent interview)
CF1637E Best Pair
How can the Solon framework easily obtain the response time of each request?
2022年贵州省职业院校技能大赛中职组网络安全赛项规程
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Pointnet++ learning
Graduation project of game mall
Summary of Haut OJ 2021 freshman week
Personal developed penetration testing tool Satania v1.2 update
Cluster script of data warehouse project
Scope of inline symbol
Add level control and logger level control of Solon logging plug-in
Solution to the palindrome string (Luogu p5041 haoi2009)
剑指 Offer 04. 二维数组中的查找
【云原生】微服务之Feign自定义配置的记录
Light a light with stm32
Bit mask of bit operation
Fried chicken nuggets and fifa22
[jailhouse article] performance measurements for hypervisors on embedded ARM processors