当前位置:网站首页>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

边栏推荐
- OpenCV关于x,y坐标容易混淆的心得
- Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
- 链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
- Learn to write article format
- Use of opencv3 6.2 low pass filter
- Common shortcut keys of Jupiter notebook (you can also view it by pressing h in command mode)
- Network security - summary and thinking of easy-to-use fuzzy tester
- Library function of C language
- Short video with goods source code, double-click to zoom in when watching the video
- Smart agriculture solutions smart agriculture system development
猜你喜欢

Carsim 学习心得-粗略翻译1

Use the kaggle training model and download your own training model

sqli-labs第12关

Openfeign is easy to use

Use of OpenCV 6.4 median filter

Chinese garbled code under vscade

Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)

Detailed explanation of NIN network

2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers

Carsim-問題Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
随机推荐
In depth understanding of prototype drawings
2022 Heilongjiang's latest eight member (Safety Officer) simulated test question bank and answers
Getting started with k8s: building MySQL with Helm
OpenFeign 簡單使用
Matlab other
Flex layout
ARP and ARP Spoofing
Learning C
ARP及ARP欺骗
2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers
Sentinel easy to use
Comparable,Comparator,Clonable 接口使用剖析
16: 00 interview, came out at 16:08, the question is really too
W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it
c语言自定义类型枚举,联合(枚举的巧妙使用,联合体大小的计算)
Opencv common method source link (continuous update)
How to uninstall SQL Server cleanly
Use Wireshark to grab TCP three handshakes
Carsim-問題Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
Makefile基本原理