CF1578D.Dragon Curve
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A dragon curve is a self-similar fractal curve. In this problem, it is a curve that consists of straight-line segments of the same length connected at right angles. A simple way to construct a dragon curve is as follows: take a strip of paper, fold it in half n times in the same direction, then partially unfold it such that the segments are joined at right angles. This is illustrated here:

In this example, a dragon curve of order 3 is constructed. In general, a dragon curve of a higher order will have a dragon curve of a lower order as its prefix. This allows us to define a dragon curve of infinite order, which is the limit of dragon curves of a finite order as the order approaches infinity.
Consider four dragon curves of infinite order. Each starts at the origin (the point (0,0)), and the length of each segment is 2. The first segments of the curves end at the points (1,1), (−1,1), (−1,−1) and (1,−1), respectively. The first turn of each curve is left (that is, the second segment of the first curve ends at the point (0,2)). In this case, every segment is a diagonal of an axis-aligned unit square with integer coordinates, and it can be proven that there is exactly one segment passing through every such square.
Given a point (x,y), your task is to find on which of the four curves lies the segment passing through the square with the opposite corners at (x,y) and (x+1,y+1), as well as the position of that segment on that curve. The curves are numbered 1 through 4. Curve 1 goes through (1,1), 2 through (−1,1), 3 through (−1,−1), and 4 through (1,−1). The segments are numbered starting with 1.
龙形曲线(dragon curve)是一种自相似分形曲线。在本题中,它是由长度相等的直线段构成的曲线,且相邻线段在连接处成直角。构造龙形曲线的一种简单方法如下:取一条纸带,沿同一方向连续对折 n 次,然后部分展开,使得各线段在直角处相连。如下图所示:

本例中构造的是 3 阶龙形曲线。一般地,高阶龙形曲线的前缀即为某低阶龙形曲线。因此,我们可以定义无限阶龙形曲线,即有限阶龙形曲线在阶数趋于无穷时的极限。
考虑四条无限阶龙形曲线。每条曲线均起始于原点 (0,0),且每条线段长度均为 2。这四条曲线的第一条线段终点分别为 (1,1)、(−1,1)、(−1,−1) 和 (1,−1)。每条曲线的第一处转向均为左转(即第一条曲线的第二条线段终点为 (0,2))。此时,每条线段均是某个边与坐标轴平行、顶点坐标为整数的单位正方形的对角线;可以证明:对于每一个这样的单位正方形,恰好有一条线段穿过它。
给定一点 (x,y),你的任务是确定:以 (x,y) 和 (x+1,y+1) 为对角顶点的单位正方形所穿过的那条线段,位于四条曲线中的哪一条上;并确定该线段在对应曲线中的编号(从 1 开始计数)。四条曲线编号为 1 至 4:曲线 1 经过 (1,1),曲线 2 经过 (−1,1),曲线 3 经过 (−1,−1),曲线 4 经过 (1,−1)。
输入格式
The first line contains an integer n (1≤n≤2⋅105) — the number of test cases.
Each of the following n lines contains two integers x and y (−109≤x,y≤109) — the coordinates.
第一行包含一个整数 n(1≤n≤2⋅105)——测试用例的数量。
接下来的 n 行中,每行包含两个整数 x 和 y(−109≤x,y≤109)——坐标。
输出格式
For each test case, print a line containing two integers — the first is the index of the curve (an integer between 1 and 4, inclusive), and the second is the position on the curve (the first segment has the position 1).
对于每个测试用例,输出一行包含两个整数——第一个是曲线的索引(一个介于 1 和 4 之间的整数,含端点),第二个是曲线上的位置(第一条线段的位置为 1)。
输入输出样例
输入#1
5 0 0 -2 0 -7 -7 5 -9 9 9
输出#1
1 1 2 2 3 189 4 186 2 68
说明/提示
You can use this illustration to debug your solution:

您可以使用此图示来调试您的解法:

输入解题思路,AI测评打分。不知道怎么写?