$ POJ3889Fractal~Streets $(模拟)



$ solution: $

这是一道淳朴的模拟题,最近发现这种题目总是可以用逼近法,就再来练练手吧。

首先对于每个编号我们可以用逼近法求出它在各个图上是处于左上,右上,左下,右下中的哪一个。

inline void bijin(int i,int v){
if(i==0)return ;
rg x=1<<(i*2-2),y=1;
while(v>x)v-=x,++y;
t[i]=y; bijin(i-1,v);
}

然后我们在用逼近法将它的坐标一步步复原。(中间会涉及旋转操作)

inline void find(int i,int x,int y,int f,su &v){
if(i>n){v.x=x; v.y=y; return ; }
rg l=1<<(i-1);
if(t[i]==1){
rg xx=x,yy=y;
x=l-yy+1;
y=l-xx+1;
}
if(t[i]==4){
rg xx=x,yy=y;
x=yy;
y=xx;
}
if(t[i]==1||t[i]==2)x+=l;
if(t[i]==2||t[i]==3)y+=l;
find(i+1,x,y,t[i],v);
}


$ code: $

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set> #define ll long long
#define db double
#define rg register int using namespace std; int n,a,b;
int t[17]; struct su{
int x,y;
}sa,sb; inline int qr(){
register char ch; register bool sign=0; rg res=0;
while(!isdigit(ch=getchar()))if(ch=='-')sign=1;
while(isdigit(ch))res=res*10+(ch^48),ch=getchar();
if(sign)return -res; else return res;
} inline void bijin(int i,int v){
if(i==0)return ;
rg x=1<<(i*2-2),y=1;
while(v>x)v-=x,++y;
t[i]=y; bijin(i-1,v);
} inline void find(int i,int x,int y,int f,su &v){
if(i>n){v.x=x; v.y=y; return ; }
rg l=1<<(i-1);
if(t[i]==1){
rg xx=x,yy=y;
x=l-yy+1;
y=l-xx+1;
}
if(t[i]==4){
rg xx=x,yy=y;
x=yy;
y=xx;
}
if(t[i]==1||t[i]==2)x+=l;
if(t[i]==2||t[i]==3)y+=l;
find(i+1,x,y,t[i],v);
} int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
rg tt=qr(); t[0]=1;
while(tt--){
n=qr(); a=qr(); b=qr();
bijin(n,a); find(1,1,1,1,sa);
bijin(n,b); find(1,1,1,1,sb);
rg x=sa.x-sb.x,y=sa.y-sb.y;
db z=sqrt((db)x*x*100+(db)y*y*100);
rg ans=(int)(z*2)-(int)z;
printf("%d\n",ans);
}
return 0;
}

POJ 3889 Fractal Streets(逼近模拟)的更多相关文章

  1. poj3889 fractal streets

    分形街道 我干,这个毒瘤. 想起来就头痛. 首先看题就是一大难题...... 说一下题目大意吧. 每当n+1时,把n阶图复制为4份.2*2排好. 右边两个不动.左上顺时针旋转90°,左下逆时针旋转90 ...

  2. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  3. POJ 1027 The Same Game(模拟)

    题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...

  4. POJ 3414 Pots【bfs模拟倒水问题】

    链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...

  5. POJ 2083 Fractal 分形题目

    这两天自学了一线算法导论里分治策略的内容,秉着只有真正投入投入编程,才能更好的理解一种算法的思想的想法,兴致勃勃地找一些入门的题来学习. 搜了一下最后把目光锁定在了Poj fractal这一个题上.以 ...

  6. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  7. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  8. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

  9. POJ 1068 Parencodings【水模拟--数括号】

    链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

随机推荐

  1. Unity各版本差异

    Unity各版本差异 version unity 5.x 4.x  2017 差异 特点  首先放出unity的下载地址,然后再慢慢分析各个版本.再者unity可以多个版本共存,只要不放在同一目录下. ...

  2. JDBC之Statement 接口的测试(存在sql注入风险)

    实现简单的登录功能 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; impo ...

  3. HDFS——完全分布式搭建

    架构 NN--namenode SNN--secondnamenode DN--datanode hadoop_env.sh中修改JAVA_HOME core-site.xml <propert ...

  4. Mac开机自动运行shell脚本

    1.首先写一个sh脚本,比如: cd ~/Documents mkdir haha 代码很简单,进入Documents文件夹,建立haha目录,保存为run.sh 2.修改run.sh权限 sudo ...

  5. Delphi XE2 之 FireMonkey 入门(7) - TText 与 TFont

    TText 也是从 TShape(TControl -> TShape)继承; 而与之类似的 TLabel 的继承序列是 TControl -> TStyledControl -> ...

  6. spring的基础配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. GMS认证测试FQA

    ---摘要 本文档用于收录GMS认证测试的异常问题,提供一般性指导.对于本文档中未提供解答的问题请咨询@开发经理或@领域技术专家 cts测试工具如何获取? A:见Google官网 https://so ...

  8. 信息收集【采集点OWASP CHINA】网址http://www.owasp.org.cn/

    以下部分源于 安全家 http://www.anquanjia.net.cn/newsinfo/729480.html 资源虽多,优质却少.不要被信息海迷惑的心智,新人要想入门,除了优质的系统教学资源 ...

  9. 027 (H5*) react01

    目录 正文 1:创建Vue项目 1: 全局安装 vue-cli cnpm install --global vue-cli 2: 创建一个基于 webpack 模板的新项目 vue init webp ...

  10. 前端 CSS的选择器 属性选择器

    属性选择器,字面意思就是根据标签中的属性,选中当前的标签. 属性选择器 通常在表单控件中 使用比较多 根据属性查找 /*用于选取带有指定属性的元素.*/ <!DOCTYPE html> & ...