模拟,贪心
小红的圆移动
https://www.nowcoder.com/practice/3d7a2818ac5746f5baf795de99a17f45
思路:模拟,贪心。我们读入数据的时候,先判断当前的圆是否包含了原点。如果包含有原点,那就计算出它的移动代价,并且存放到一个临时数组中。之后就判断一下这个数组的长度是否<=k,如果是直接输出0即可;否则,我们要先把代价从小到大排序,然后取前length - k个元素。
代码:
import sys
input = lambda: sys.stdin.readline().strip()
import math
inf = 10 ** 18
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LI():
return input().split()
def LII():
return list(map(int, input().split()))
def LFI():
return list(map(float, input().split()))
fmax = lambda x, y: x if x > y else y
fmin = lambda x, y: x if x < y else y
isqrt = lambda x: int(math.sqrt(x))
'''
'''
def solve():
n, k = MII()
pi = math.pi
in_circle = []
for _ in range(n):
x, y, r = LII()
d = math.sqrt(x * x + y * y)
if r > d:
in_circle.append(pi * r * r * (r - d))
if len(in_circle) <= k:
print(0)
else:
in_circle.sort()
print(sum(in_circle[:len(in_circle) - k]))
t = 1
# t = II()
for _ in range(t):
solve()
#每日一题挑战#

SHEIN希音公司福利 284人发布