链接:登录—专业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