当前位置:网站首页>(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
2022-08-01 04:50:00 【AC__dream】
Title: 
Sample input:
41234Sample output:
40 0 1 180 1 1 21 1 2 20 0 2 1142 1 3 23 1 4 24 1 5 23 0 5 10 1 2 20 0 3 1184 0 5 12 3 3 43 3 4 44 3 5 43 1 5 23 2 5 30 3 2 40 1 3 20 2 3 30 0 4 1Title: Given n 1*1 rectangles, n-1 1*2 rectangles, n-2 1*3 rectangles, and 1 1*n rectangle, splicing these rectangles into a largeRectangle, find the minimum perimeter of the larger rectangle.
Analysis: I looked at the data range and found that n is less than 200.Due to how we spliced, the area of the rectangle formed at the end must be fixed. There is an obvious reason that In the case of a certain area, the smaller the difference between the length and the width, the smaller the perimeter.The smaller it is, because ab<=((a+b)/2)^2 can be obtained from the mean inequality, and the equal sign is obtained when a=b, so we must start from the square root of the areaEnumerate the length and width, and then judge whether the given multiple small rectangles can be spliced into a w*h rectangle one by one, and write a separate function to judge. For example, if we enumerate the width, then the first one of a rectangle can be formed.The condition is S%w*w==S, and the second is to see if it can be obtained by splicing with small rectangles.So how do we judge whether it can be obtained by splicing with small rectangles?There is a greedy strategy that says We try to choose a large rectangle every time we fill it, why is this necessarily optimal?In fact, if we need a 1*x rectangle now, we can use a 1*x rectangle or multiple smaller rectangles. When we need a smaller rectangle, the 1*x rectangle isThere is no way to separate, but we can fill with small rectangles, and any time a small rectangle can replace a large rectangle, so this greed must be correct.
Finally, we use a vector p[i] to record the width of the small rectangle filled in the i-th row
Here is the code:
#include#include#include#include#include 边栏推荐
- [kali-information collection] enumeration - DNS enumeration: DNSenum, fierce
- Excel record of integer programming optimization model to solve the problem
- 时时刻刻保持敬畏之心
- This article takes you to understand the past and present of Mimir, Grafana's latest open source project
- Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers
- Excel做题记录——整数规划优化模型
- (more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)
- Passive anti-islanding-UVP/OVP and UFP/OFP passive anti-islanding model simulation based on simulink
- typescript25 - type assertion
- typescript26 - literal types
猜你喜欢

API Design Notes: The pimpl trick
![Invalid classes inferred from unique values of `y`. Expected: [0 1 2], got [1 2 3]](/img/53/3dc2233498db78b8480084ce496f0b.png)
Invalid classes inferred from unique values of `y`. Expected: [0 1 2], got [1 2 3]

剑指 Offer 68 - I. 二叉搜索树的最近公共祖先

【愚公系列】2022年07月 Go教学课程 023-Go容器之列表

typescript20-接口

Typescript20 - interface

律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性

(2022牛客多校四)N-Particle Arts(思维)

Typescript22 - interface inheritance

(2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)
随机推荐
智芯传感输液泵压力传感器 为精准智能控制注入科技“强心剂”
TIM登陆时提示00001(TIM00001)
李迟2022年7月工作生活总结
LeetCode 387. 字符串中的第一个唯一字符
Typescript22 - interface inheritance
typescript24-类型推论
August 22 Promotion Ambassador Extra Reward Rules
C# | 使用Json序列化对象时忽略只读的属性
高数 | 【重积分】线面积分880例题
"ArchSummit: The cry of the times, technical people can hear"
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
6-23漏洞利用-postgresql代码执行利用
请问shake数据库中想把源的db0的数据同步到目的db5,参数怎么设置呢?
PMP子过程定义总结
lambda
律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性
项目风险管理必备内容总结
Difference Between Compiled and Interpreted Languages
scheduleWithFixedDelay和scheduleAtFixedRate的区别
【愚公系列】2022年07月 .NET架构班 085-微服务专题 Abp vNext微服务网关