POJ 3889 Fractal Streets(逼近模拟)
$ 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(逼近模拟)的更多相关文章
- poj3889 fractal streets
分形街道 我干,这个毒瘤. 想起来就头痛. 首先看题就是一大难题...... 说一下题目大意吧. 每当n+1时,把n阶图复制为4份.2*2排好. 右边两个不动.左上顺时针旋转90°,左下逆时针旋转90 ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 1027 The Same Game(模拟)
题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- POJ 2083 Fractal 分形题目
这两天自学了一线算法导论里分治策略的内容,秉着只有真正投入投入编程,才能更好的理解一种算法的思想的想法,兴致勃勃地找一些入门的题来学习. 搜了一下最后把目光锁定在了Poj fractal这一个题上.以 ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
- POJ 1068 Parencodings【水模拟--数括号】
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
随机推荐
- kubernetes-helm程序包管理器(二十)
helm概述 Helm是Kubernetes的包管理器,Helm 让我们能够像 yum 管理 rpm 包那样安装.部署.升级和删除容器化应用. Helm的核心术语: Chart:一个helm程序包,是 ...
- customizable route planning 工业界地图产品的路径规划
https://www.microsoft.com/en-us/research/publication/customizable-route-planning/?from=http%3A%2F%2F ...
- 10.6 Comment Syntax
w https://dev.mysql.com/doc/refman/5.7/en/comments.html MySQL 5.7 Reference Manual / Language Stru ...
- spring boot 1.5.10.RELEASE ,spring boot admin 1.5.7 添加 security
生产环境的客户端actuator最好是加上security校验,不然配置信息不登录就能直接获取到 server端配置,参考官方 文档,https://codecentric.github.io/spr ...
- Jmeter JDBC请求-----数据库读取数据进行参数化 通过SSH跳板机连接数据库
前期准备: jdbc驱动:mysql-connector-java-5.1.7-bin.jar Jmeter 要链接MySQL数据库,首选需要下载mysql jdbc驱动包(注:驱动包的版本一定要与你 ...
- day16模块,导入模板完成的三件事,起别名,模块的分类,模块的加载顺序,环境变量,from...import语法导入,from...import *,链式导入,循环导入
复习 ''' 1.生成器中的send方法 -- 给当前停止的yield发生信息 -- 内部调用__next__()取到下一个yield的返回值 2.递归:函数的(直接,间接)自调用 -- 回溯 与 递 ...
- 宝塔 windows下apache环境下禁止某文件夹内运行PHP脚本、禁止访问文件
首先我们来看两段对上传目录设置无权限的列子,配置如下: //在宝塔下如用/upload这个路径应用无效,一定要C:/wwwroot/upload才有效果 <Directory "要去掉 ...
- STL关联式容器之set\map ----以STL源码为例
关联式容器的特征:所用元素都会根据元素的键值自动被排序. set STL 中的关联式容器低层数据结构为红黑树,其功能都是调用低层数据结构中提供的相应接口. set元的元素不会像map那样同时拥有键(k ...
- [Git] 004 初识 Git 与 GitHub 之查看历史记录
在 GitHub 的 UI 界面使用 Git 查看历史纪录 1. 右侧有个 history 2. 点击后跳转页面 3. 点击相应标题(commit 时写的),进入相应版本(历史) 4. 我选择了 I ...
- Git-第五篇廖雪峰Git教程学习笔记(4)分支
1.一开始,只有一个主分支(master),HEAD指向Master,而Master指向主分支.现在我们创建dev分支. lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/git ...