当前位置:网站首页>Luogu greedy part of the backpack line segment covers the queue to receive water
Luogu greedy part of the backpack line segment covers the queue to receive water
2022-07-02 08:34:00 【A sensible pigeon】
P2240 【 Deep base 12. example 1】 Part of the knapsack problem
According to the greedy strategy , First, calculate the cost performance , Then sort by cost performance from large to small , As long as it doesn't reach the weight of the backpack , Just load .
Data structure selection
python No structure , Select two-dimensional array ( Value of goods 、 weight ) Store individual items for easy sorting
num,capacity=map(int,input().split())
arr=[[10000000,0.1] for i in range(101)]
for i in range(num):
arr[i]=input().split()
arr[i]=[int(j) for j in arr[i]]
# arr[i].append(i)
# print(arr[i])
arr.sort(key=lambda arr:arr[1]/arr[0],reverse=True)
sum=0
for item in arr:
if capacity<item[0]:
sum+=capacity*item[1]/item[0]
break
sum+=item[1]
capacity-=item[0]
print('%.2f'%sum)
P1223 Line up for water

P1803 Line segments cover

边栏推荐
猜你喜欢

c语言将字符串中的空格替换成%20

路由基础—动态路由

C language custom type enumeration, Union (clever use of enumeration, calculation of union size)

Generate database documents with one click, which can be called swagger in the database industry

STM32-新建工程(参考正点原子)

HCIA—應用層

Realization of basic function of sequence table

链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)

Sentinel 简单使用

Valin cable: BI application promotes enterprise digital transformation
随机推荐
使用wireshark抓取Tcp三次握手
OpenCV 6.4 中值滤波器的使用
Openfeign facile à utiliser
Honeypot attack and defense drill landing application scheme
Learning C
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
File upload Labs
sqli-labs第8关(布尔盲注)
Use of opencv3 6.2 low pass filter
OpenFeign 简单使用
Routing foundation - dynamic routing
Hcia - Application Layer
How to uninstall SQL Server cleanly
When a custom exception encounters reflection
Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
HCIA - application layer
C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)
Sentinel 简单使用
idea中注释代码取消代码的快捷键