$ 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. 【转】DataRow复制一行到另一个DataTable

     源地址:http://www.cnblogs.com/pains/archive/2007/11/22/969003.html   下面两个方法是DataRow复制一行到另一个DataTable的, ...

  2. hashcode、equals、HashMap间的关系

    1.从Object说起package com.hallo.collection; public class ObjectDemo { public static void main(String[] ...

  3. 使用spring提供的@Scheduled注解创建定时任务

    使用方法 操作非常简单,只要按如下几个步骤配置即可 1. 导入jar包或添加依赖,其实定时任务只需要spring-context即可,当然起服务还需要spring-web: 2. 编写定时任务类和方法 ...

  4. 操作Redis--hash/key-value

    redis也是一个数据库,它的存储以key-value的方式存放,比如: a.关系型数据库 比如: mysql.oracle.sql server.db2.sqlite数据库,为关系型数据库 数据通过 ...

  5. 类InetAddress

    如果一个类没有构造方法:A:成员全部是静态的(Math,Arrays,Collections)B:单例设计模式(Runtime)C:类中有静态方法返回该类的对象(InetAddress) public ...

  6. 简单DP入门(一) 数字三角形

    数字三角形

  7. debian下使用shell脚本时出现了 declare:not found 解决方法

    问题:出现declare:not found的提示 解决:原来,UBUNTU用的是dash(后来证明这个其实这个不是错误的原因:从#!/bin/bash到#!/bin/dash,依旧无法运行,在这写出 ...

  8. Queen Attack -- 微软2017年预科生计划在线编程笔试第二场

    #!/usr/bin/env python # coding:utf-8 # Queen Attack # https://hihocoder.com/problemset/problem/1497 ...

  9. Linux下修改时间及date使用

    [root@host1 ~]# date #显示时间 2017年 06月 01日 星期四 17:02:59 CST 以指定格式显示时间: [root@host1 ~]# date +%Y%m%d 20 ...

  10. <每日一题> Day1:CodeForces.1140D.MinimumTriangulation(思维题)

    题目链接 参考代码: #include <iostream> using namespace std; int main() { ; int n; cin >> n; ; i ...