Fractal Streets

POJ

题意:随着越来越大的城市对现代化的不断增长的需求,人们需要新的街道设计。克里斯是负责这些设计的不幸城市规划者之一。每年的需求都在不断增加,今年他甚至被要求设计一个全新的城市。克里斯现在需要做更多的工作,因为像任何好官僚一样,他非常懒惰。鉴于这是他与大多数计算机科学家共同的性格特征,他的一个最亲密的朋友保罗实际上是计算机科学家也就不足为奇了。正是保罗提出了一个让克里斯成为同龄人英雄的好主意:分形街!通过使用希尔伯特曲线,他可以轻松填充任意大小的矩形图,只需很少的工作。 1阶的希尔伯特曲线由一个“杯”组成。在2阶Hilbert曲线中,杯子由四个较小但相同的杯子和三个连接道路代替。在3阶Hilbert曲线中,这四个杯子又被四个相同但更小的杯子和三个连接道路等替换。在杯子的每个角落,一个车道(带有邮箱)被放置用于房屋,具有简单的连续性编号。左上角的房子是1号,两个相邻房子之间的距离是10米。 图2显示了这种情况。正如您所看到的,Fractal Streets概念成功地消除了对无聊街道网格的需求,同时仍然需要我们的官僚们付出很少的努力。 为了表达他们的感激之情,几位市长为克里斯提供了一个房子,这个房子位于用他自己的新计划建造的许多新街区之一。克里斯现在想知道哪些产品会让他最接近当地城市规划办公室(当然这些新社区中的每一个都有一个)。幸运的是,他不必在街上开车,因为他的新公司“汽车”就是那些新的飞行汽车之一。这种高科技车辆允许他从他的车道直线行驶到他新办公室的车道。你能编写一个程序来确定每个飞行员必须飞行的距离(不包括起飞和着陆时的垂直距离)吗?

分析:

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
    int x=0,o=1;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')o=-1,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline pair<int,int> calc(int n,int m){
    if(!n)return make_pair(0,0);
    int len=1<<(n-1),cnt=1<<(2*n-2);
    pair<int,int>pos=calc(n-1,m%cnt);
    int x=pos.first,y=pos.second,z=m/cnt;
    if(z==0)return make_pair(y,x);
    if(z==1)return make_pair(x,y+len);
    if(z==2)return make_pair(x+len,y+len);
    if(z==3)return make_pair(2*len-y-1,len-x-1);
}
inline double pf(int x){return 1.0*x*x;}
int main(){
    int T=read();
    while(T--){
        int n=read(),x=read(),y=read();--x;--y;
        pair<int,int>a=calc(n,x),b=calc(n,y);
        double ans=sqrt(pf(a.first-b.first)+pf(a.second-b.second))*10.0;
        printf("%.0lf\n",ans);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/PPXppx/p/11235747.html

时间: 2024-07-31 22:27:08

Fractal Streets的相关文章

POJ3889 Fractal Streets

我对分治的理解:https://www.cnblogs.com/AKMer/p/9728574.html 题目传送门:http://poj.org/problem?id=3889 据说这种图叫分形图--一般找找规律就好了,像我这种菜鸡也只会做变化小一点的分形图了. 时间复杂度:\(O(能过)\) 空间复杂度:\(O(1)\) 代码如下: #include <cmath> #include <cstdio> using namespace std; int read() { int

poj3889 Fractal Streets 题解报告

题目传送门 [题目大意] 社区的设计有一种特殊的规律,从左上角起沿着道路给房子编号,求给定编号的两间房子的距离. [思路分析] 分析可得社区的设计规律,编号为$n$,即有$4^n$个小格子,每$4^{n-1}$个小格子为一个大格子,即整个图分为四部分,其中右上和右下两部分与编号为$n-1$的相同,左上是顺时针旋转90度的结果,左下是逆时针旋转90度的结果. 代码实现的过程中注意一下这几种不同的情况,计算出坐标后直接求距离. [代码实现] 1 #include<cstdio> 2 #includ

POJ3889Fractal Streets

Fractal Streets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 445   Accepted: 162 Description With a growing desire for modernization in our increasingly larger cities comes a need for new street designs. Chris is one of the unfortunat

算法竞赛进阶指南做题记录

基本算法 递归与递推 费解的开关 Strange Towers of Hanoi Sumdiv Fractal Streets 前缀和与差分 激光炸弹 IncDec Sequence Tallest Cow 二分 Best Cow Fences 排序 Cinema 货舱选址 七夕祭 Running Median 第K大数 Ultra-QuickSort 奇数码问题 原文地址:https://www.cnblogs.com/Maktub-blog/p/11009723.html

POJ1941 The Sierpinski Fractal

Description Consider a regular triangular area, divide it into four equal triangles of half height and remove the one in the middle. Apply the same operation recursively to each of the three remaining triangles. If we repeated this procedure infinite

uva 11595 - Crossing Streets EXTREME(切割多边形)

题目链接:uva 11595 - Crossing Streets EXTREME 对初始平面进行切割,得到所有平面,然后处理出所有边,有公共边的两个平面之间可以到达,对于城市的权值可以加到点上,进出各加一次即可. #include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <complex> #in

Fractal(递归,好题)

Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8341   Accepted: 3965 Description A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not exhibit exactly

分形树Fractal tree介绍——具体如何结合TokuDB还没有太懂,先记住其和LSM都是一样的适合写密集

在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文章讲的是TokuDB,不是innodb,相比innodb,TokuDB有着自己的特点. 转自:http://www.kryptosx.info/archives/931.html BTree和Fractal tree的比较: 目前无论是SQL Server,还是MySQL的innodb,都是用的B+

POJ 题目2083 Fractal(分治)

Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7937   Accepted: 3807 Description A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not exhibit exactly