Wall Builder II题解报告


链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网

题目描述

As the builder employed by NIO, you need to build more walls for him. Now you have a number of bricks of height 1 but with different lengths. More precisely, you have nnn bricks of length 1, n−1 bricks of length 2, …, two bricks of length n−1, and one brick of length n. The width of the bricks is negligible. You need to build a wall with these bricks whose shape must be strictly rectangular. When building the wall, you must keep the height of the bricks at 1, which means you cannot rotate them.

Of course, you can definitely build a wall with a height of 111 and a large length, but it is not a beautiful wall. In NIO’s opinion, a beautiful wall should have the minimum possible circumference. Please tell him the minimum circumference of the wall, and how to build it.

输入描述:
The first line contains an integer T (1≤T≤100), indicating the number of test cases.

Each test case contains an integer nnn (1≤n≤100) in a single line. It is guaranteed that the sum of nnn over all test cases won’t exceed 200.
输出描述:
For each test case, output an integer in a single line, indicating the minimum circumference of the wall. Then in the next ​ lines, each line contains four integers x1,y1,x2,y2, indicating that the coordinate of the lower left of the brick is (x1,y1), and the upper right is (x2​,y2​).

You can consider the wall as a rectangular in the Cartesian coordinate system, where the xxx-axis represents the length and the yyy-axis represents the height. The lower left of the wall must be located at (0,0)(0,0)(0,0). If there are multiple solutions, output any.
输入
4
1
2
3
4
输出
4
0 0 1 1
8
0 1 1 2
1 1 2 2
0 0 2 1
14
2 1 3 2
3 1 4 2
4 1 5 2
3 0 5 1
0 1 2 2
0 0 3 1
18
4 0 5 1
2 3 3 4
3 3 4 4
4 3 5 4
3 1 5 2
3 2 5 3
0 3 2 4
0 1 3 2
0 2 3 3
0 0 4 1
说明
A possible solution for the third test case in the sample:在这里插入图片描述
题目大意:有许多高度为1但长度不同的砖块,具体而言,有n块长度为1的砖块,有n - 1块长度为2砖块…有2块长度为n- 1的砖块,有1块长度为n的砖块。将这样砖块搭建一个严格矩形, 求最小周长下的搭建方案。
思路:先将n块砖头的总面积算出来,再将其开更号(众所皆知,矩形两边差越小,它的周长越小),然后进入循环,用循环变量i暴力枚举(从更号s开始到1)再判断矩形长宽是否符合要求,若符合,则直接跳出,输出,若不符,继续。
本程序中,判断交给check(),输出交给print().
参考代码

#include<bits/stdc++.h>
using namespace std
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值