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

建议使用的浏览器:

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

1246:Hilbert Curve Intersections

题目描述

David Hilbert proved the existence of a very counter-intuitive curve that fills space. The construction of the Hilbert curve is based on a sequence of curves, H1, H2, H3, H4, ... composed of horizontal and vertical segments. Each curve lies in the unit square [0, 1] * [0, 1]. H1 contains just three segments, connecting the points (1/4, 3/4) to (1/4, 1/4) to (3/4, 1/4) to (3/4, 3/4). Hn is defined recursively in terms of Hn-1, for n = 2, 3, ... by four transformations:

1.Halve all coordinates in Hn-1.
2.Add a copy rotated 90 degrees counterclockwise about the point (0, 1/2).
3.Add the reflection across the line x = 1/2.
4.Let m = 1/2n+1. Add segments connecting endpoints (1/2 - m, 1/2 - m) to (1/2 + m, 1/2 - m), (m, 1/2 - m) to (m, 1/2 + m), and (1 - m, 1/2 - m) to (1 - m, 1/2 + m).
Your job is to count the number of intersections of horizontal line segments with these curves. For example, consider Figures 1 and 2, which illustrate the first two example input data sets below.

The coordinates of vertices of Hn are odd multiples of 1/2n+1. The coordinates of horizontal segment endpoints will always be multiples of 1/2n. Hence the specified horizontal segment can only cross vertical segments in Hn.
输入解释
Input consists of one to 100 data sets, one per line, followed by a final line containing only 0. Each data set consists of four integers separated by blanks in the form
n x1 x2 y
which represents Hn and the segment from (x1/2n, y/2n) to (x2/2n, y/2n), where 0 < n < 31, x1 < x2, and each of x1, x2, and y lie in the range 0 to 2n, inclusive.
输出解释
The output is one integer per line for each data set: the number of intersections of Hn with the segment. Caution: A brute force solution that computes each intersection individually will not finish within the one minute time limit. As you can see below, there may be more than one billion intersections for any data set.
输入样例
3 2 7 7
4 0 16 1
30 1 1073741823 1
0
输出样例
3
16
1073741822

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

题目来源 Mid-Central USA 2002

源链接: POJ-1246

最后修改于 2020-10-29T05:58:47+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000