#P6913. [ICPC2015 WF] Tile Cutting

[ICPC2015 WF] Tile Cutting

题目描述

Youssef is a Moroccan tile installer who specializes in mosaics like the one shown on the right. He has rectangular tiles of many dimensions at his disposal, and the dimensions of all his tiles are integer numbers of centimeters. When Youssef needs parallelogram-shaped tiles, he cuts them from his supply on hand. To make this work easier, he invented a tile cutting machine that superimposes a centimeter grid on the cutting surface to guide the cuts on the tiles. Due to machine limitations, aesthetic sensibilities, and Youssef’s dislike of wasted tiles, the following rules determine the possible cuts.

The rectangular tile to be cut must be positioned in the bottom left corner of the cutting surface and the edges must be aligned with the grid lines.

The cutting blade can cut along any line connecting two different grid points on the tile boundary as long as the points are on adjacent boundary edges.

The four corners of the resulting parallelogram tile must lie on the four sides of the original rectangular tile.

No edge of the parallelogram tile can lie along an edge of the rectangular tile.

Figure 1 shows the eight different ways in which a parallelogram tile of area 44 square centimeters can be cut out of a rectangular tile, subject to these restrictions.

Figure 1: The eight different ways for cutting a parallelogram of area 4.

Youssef needs to cut tiles of every area between aloa_{\text {lo}} and ahia_{\text {hi}}. Now he wonders, for which area aa in this range can he cut the maximum number of different tiles?

输入格式

The input consists of multiple test cases. The first line of input contains an integer nn (1n5001 \le n \le 500), the number of test cases. The next nn lines each contain two integers alo,ahia_{\text {lo}}, a_{\text {hi}} ($1 \le a_{\text {lo}} \le a_{\text {hi}} \le 500\, 000$), the range of areas of the tiles.

输出格式

For each test case aloa_{\text {lo}}, ahia_{\text {hi}}, display the value aa between aloa_{\text {lo}} and ahia_{\text {hi}} such that the number of possible ways to cut a parallelogram of area aa is maximized as well as the number of different ways ww in which such a parallelogram can be cut. If there are multiple possible values of aa display the smallest one.

题目大意

Youssef是一名专业贴瓷砖的修墙工,并且擅长用瓷砖贴出马赛克图案(如上图所示)。所有的瓷砖的尺寸长度均为整数,单位为cmcm。在马赛克图案中,平行四边形是不可或缺的。因此,Youssef会使用切割机,将矩形的瓷砖进行切割。在切割过程中,Youssef选择使用网格辅助切割机进行切割(在瓷砖上布上cmcm的网格方便切割)。

切割过程有以下要求:
  1. 可以从两个不同端点的连线切割(可以斜着切割)
  2. 新平行四边形的四个角必须在矩形瓷砖的最外侧边上
  3. 平行四边形的边不能与矩形的任意一条边边重叠

现在给出切割的面积的两个边界值aloa_{lo}ahia_{hi},求出Youssef能够最多切割掉的小矩形瓷砖数量。

输入格式:

给出测试样例数量nn(1n5001≤n≤500)。下面nn行给出切割面积的两个边界值aloa_{lo}ahia_{hi}1aloahi5000001≤a_{lo}≤a_{hi}≤500 000

输出格式:

每行先输出平行四边形面积aa,再输出小矩形最多切割数量ww。如果aa有不同值的时候,输出最小的即可。

2
4 4
2 6

4 8
6 20

提示

Time limit: 11000 ms, Memory limit: 1048576 kB.

International Collegiate Programming Contest (ACM-ICPC) World Finals 2015