当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3060:Make it Manhattan

题目描述
Chaos City has grown out of control. Building have been built everywhere and the city layout is a complete mess. The mayor decided that this must come to an end, and wants to create a nice, structed city.

After some research, he found the ideal way to make this happen. Inspired by the New York district of Manhanttan, he wants all buidlings organized in a rectangular grid, separated by avenuesrunning from North to South and streets running from West to East. These streets and avenues should all be separated by the same distance D.

In the current situation, the buidlings are already organized in a rectangular grid. In fact each buidling fills exactly one square in this grid. However, with all the buildings randomly scattered across the city, it may be impossible to build the roads without demolishing a couple of buildings. To keep most citizens happy, the mayor wants to demolish as few buidlings as possible. Given the current locations of the buidlings, what's this minimum number?

The above picture illustrates the problem. The shaded squares are the initial locations of the buidlings. If the roads should be separated by a distance of three, the thick lines indicate the optimal placement of the roads and one building has to be demolished.
输入解释
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
One line with two integers D and N, separated by a single space, satisfying 1 <=D <= 1000 and 0 <= N <= 100000: the distance between two roads, and the number of buidling in the city respectively.
N lines with two integers xi and yi, separated by a single space, satisfying -109 <= xi, yi <= 109: the positions of the buidlings.
输出解释
For every testcase in the input, the output should contains a single line with the minimum number of buidling that has to be demolished.
输入样例
1
3 10
1 0
2 0
3 0
4 0
1 2
0 3
1 5
3 5
4 2
-2 2
输出样例
1

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3060

最后修改于 2020-10-29T06:51:29+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000 65536