Acwing_98
创始人
2024-03-22 14:42:20
0

题目链接

考察知识点: 坐标变换、递归、分治。


核心问题:计算出点的坐标。

策略是递归算出子图形中的坐标,再进行平移得到当前图形中的坐标。

采用下图方式建立坐标系:原点在中心。

在这里插入图片描述

前置知识:

(x,y)(x,y)(x,y) 逆时针旋转 θ\thetaθ 角度,坐标为 (xcos⁡θ−ysin⁡θ,xsin⁡θ−ycos⁡θ)(x\cos\theta-y\sin\theta,x\sin\theta-y\cos\theta)(xcosθ−ysinθ,xsinθ−ycosθ) 。

设 nnn 为等级,mmm 为在等级为 nnn 时的编号。

单位长度=2n单位长度=2^{n}单位长度=2n 。

len=单位长度2=2n−1len = \frac{单位长度}{2} = 2^{n-1}len=2单位长度​=2n−1 。

m=4n=22nm=4^{n}=2^{2n}m=4n=22n 。

等级 222 的 000 号图形是由等级 111 的图形顺时针旋转 90°90°90° ,再进行 yyy 轴轴对称得到。

假设在等级 111 中的坐标为 (x,y)(x,y)(x,y) ,旋转后为 (y,−x)(y,-x)(y,−x) ,再进行关于 yyy 轴的轴对称得到 (−y,−x)(-y,-x)(−y,−x) 。

同理可以得到如下表格:

原始坐标图形0中坐标图形1中坐标图形2中坐标图形3中坐标
(x,y)(x,y)(x,y)(−y,−x)(-y,-x)(−y,−x)(x,y)(x,y)(x,y)(x,y)(x,y)(x,y)(y,x)(y,x)(y,x)

因为等级 111 的原点和等级 222 的原点不重合,所以需要将原点进行平移。

原点平移后得到最终坐标如下:

原始坐标图形0图形1图形2图形3
$(x,y) $(−y−len,−x+len)(-y-len,-x+len)(−y−len,−x+len)(x+len,y+len)(x+len,y+len)(x+len,y+len)(x+len,y−len)(x+len,y-len)(x+len,y−len)(y−len,x−len)(y-len,x-len)(y−len,x−len)

我们的编号从 000 开始,计算坐标注意减一。

时间复杂度: O(n)O(n)O(n)

代码

// #pragma GCC optimize(3)
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
// #include 
// #include 
#define endl '\n'
#define x first
#define y second
#define fi first
#define se second
#define PI acos(-1)
// #define PI 3.1415926
#define LL long long
#define INF 0x3f3f3f3f
#define lowbit(x) (-x&x)
#define ULL unsigned LL
#define PLL pair
#define PIL pair
#define PII pair
#define all(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof a)
#define rev(x) reverse(x.begin(), x.end())
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)using namespace std;LL n, a, b;PLL calc(LL n, LL m) {if (n == 0) return {0, 0};LL len = 1ll << (n - 1), cnt = 1ll << (2 * n - 2);PLL pos = calc(n - 1, m % cnt);LL x = pos.x, y = pos.y;int z = m / cnt;if (z == 0) {return {-y - len, -x + len};} else if (z == 1) {return {x + len, y + len};} else if (z == 2) {return {x + len, y - len};} return {y - len, x - len};
}void solve() {int tt;cin >> tt;while (tt -- ) {cin >> n >> a >> b;PLL ac = calc(n, a - 1), bc = calc(n, b - 1);double dx = ac.x - bc.x, dy = ac.y - bc.y;    	printf("%.0lf\n", sqrt(dx * dx + dy * dy) * 5);}
}int main() {IOS;solve();return 0;
}

相关内容

热门资讯

爱回收、同城帮二手回收乱象:砍... 出品|搜狐科技 作者|郑松毅 编辑|杨锦 家里放着淘汰的旧手机,想卖掉回血却怕踩坑?不少人都抱着“能...
青海五年完成省级地方性法规和规... 中新网西宁12月27日电(祁增蓓)26日,记者从“‘十四五’发展成就”系列主题新闻发布会青海省司法厅...
新《海商法》中海上货物运输制度... 开栏寄语 《中华人民共和国海商法》完成全面修订并正式实施,这标志着我国海事法治建设进入新阶段,为加快...
2025年读书笔记(上):《乔... 小崔律师认为书单与歌单一样,实际上是非常私人化的内容,只有选择而无好坏之分,所谓的推荐其实只是对20...
原创 政... 忍无可忍的食堂承包商的一纸实名举报,撕开了河南省周口市淮阳人民中学从餐费中强行超高抽成,从学生口中夺...
小学女教师和校长的“窗帘纠纷”... 近日,关于一名女教师向校长申请安装窗帘遭到拒绝的事件,有了最新进展。 根据报道,该女教师所在的班级...
年度盘点丨十大关键词,看楼市政... 获取最新政策解读报告 ☞ 戳这里,加入地产/物业/投拓/产城 展望2026年,稳楼市的主基调延续,...
原创 韩... 韩国这回跟日本杠上了,不仅起诉了“靖国神社”,还要求日本政府赔钱,高市早苗的麻烦事儿,可真是一桩接着...
甘肃省镇原县人民法院:“小额诉... “法院拿出的一揽子方案,既考虑了我们企业的实际情况,也兼顾双方的合法权益,我们还愿继续合作!” 日前...
甘肃省民乐县人民法院诉讼服务中... “不到十分钟就完成了从咨询到立案的全部流程!”近日,一企业办事人员在法院干警的指导下,通过涉企绿色通...