当前位置:网站首页>(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 边栏推荐
- 请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
- Invalid classes inferred from unique values of `y`. Expected: [0 1 2], got [1 2 3]
- What is dynamic programming and what is the knapsack problem
- Passive anti-islanding-UVP/OVP and UFP/OFP passive anti-islanding model simulation based on simulink
- 56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
- 云服务器下载安装mongo数据库并远程连接详细图文版本(全)
- typescript26 - literal types
- 故乡的素描画
- 在互联网时代,有诸多「互联网+」模式的诞生
- 报错:AttributeError: module ‘matplotlib’ has no attribute ‘figure’
猜你喜欢

typescript28 - value of enumeration type and data enumeration

typescript26 - literal types

This article takes you to understand the past and present of Mimir, Grafana's latest open source project

Optional parameters typescript19 - object

故乡的素描画

认真对待每一个时刻

Step by step hand tearing carousel Figure 3 (nanny level tutorial)

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

怀念故乡的面条

UE4 模型OnClick事件不生效的两种原因
随机推荐
Flink 1.13 (8) CDC
【堆】小红的数组
y83. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (14)
项目风险管理必备内容总结
今日睡眠质量记录68分
微软 Win10 照片磁贴后的又一“刺客”,谷歌 Chrome 浏览器将在新标签页展示用户照片
How to promote new products online?
How to write a high-quality digital good article recommendation
云服务器下载安装mongo数据库并远程连接详细图文版本(全)
阿叶的目标
MLP neural network, GRNN neural network, SVM neural network and deep learning neural network compare and identify human health and non-health data
SQL Analysis of ShardingSphere
scheduleWithFixedDelay和scheduleAtFixedRate的区别
(2022牛客多校四)A-Task Computing (排序+动态规划)
The Principle Of Percona Toolkit Nibble Algorithm
typescript23-元组
[target detection] YOLOv7 theoretical introduction + practical test
PAT乙级 1001 害死人不偿命的(3n+1)猜想
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
【愚公系列】2022年07月 Go教学课程 024-函数