当前位置:网站首页>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
边栏推荐
- Sqli labs Level 2
- Data asset management function
- ARP及ARP欺骗
- Global and Chinese markets of tilting feeders 2022-2028: Research Report on technology, participants, trends, market size and share
- Network security - summary and thinking of easy-to-use fuzzy tester
- HCIA—應用層
- Carsim-路面3D形状文件参数介绍
- How to uninstall SQL Server cleanly
- Constant pointer and pointer constant
- 链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
猜你喜欢
Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
Carsim 学习心得-粗略翻译1
sqli-labs第12关
Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
什么是SQL注入
C language replaces spaces in strings with%20
DWORD ptr[]
Carsim-路面3D形状文件参数介绍
Web security -- Logical ultra vires
随机推荐
什么是SQL注入
Mutex
Intelligent manufacturing solutions digital twin smart factory
Valin cable: BI application promotes enterprise digital transformation
CarSim learning experience - rough translation 1
Global and Chinese market of electric cheese grinder 2022-2028: Research Report on technology, participants, trends, market size and share
STM32 new project (refer to punctual atom)
What are the platforms for selling green label domain names? What is the green label domain name like?
sqli-labs第12关
Use of OpenCV 6.4 median filter
C language replaces spaces in strings with%20
Carsim-问题Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
IP protocol and IP address
Don't know mock test yet? An article to familiarize you with mock
Carsim 学习心得-粗略翻译1
Smart agriculture solutions smart agriculture system development
Use the kaggle training model and download your own training model
HCIA—数据链路层
Zipkin is easy to use
Force deduction method summary: double pointer