Fractal

时间限制:1000ms

单点时限:1000ms

内存限制:256MB

描述

This is the logo of PKUACM 2016. More specifically, the logo is generated as follows:

1. Put four points A0(0,0), B0(0,1), C0(1,1), D0(1,0) on a cartesian coordinate system.

2. Link A0B0, B0C0, C0D0, D0A0 separately, forming square A0B0C0D0.

3. Assume we have already generated square AiBiCiDi, then square Ai+1Bi+1Ci+1Di+1 is generated by linking the midpoints of AiBi, BiCi, CiDi and DiAi successively.

4. Repeat step three 1000 times.

Now the designer decides to add a vertical line x=k to this logo( 0<= k < 0.5, and for k, there will be at most 8 digits after the decimal point). He wants to know the number of common points between the new line and the original logo.

输入

In the first line there’s an integer T( T < 10,000), indicating the number of test cases.

Then T lines follow, each describing a test case. Each line contains an float number k, meaning that you should calculate the number of common points between line x = k and the logo.

输出

For each test case, print a line containing one integer indicating the answer. If there are infinity common points, print -1.

样例输入
3
0.375
0.001
0.478
样例输出
-1
4
20
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long LL;
const LL INF = 0xfffffff;
const int maxn = 105;
const LL MOD = 1e9+7;
double as[2000];
int main()
{
    int T, ok, ans, i;
    double a=0, b=0.5;
    for(i = 1; i <= 1000; i++)
    {
        as[i] = (a+b)/2;
        a = (a+b)/2;
    }
    double x;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%lf", &x); ok = 0;
        for(i = 0; i <= 1000; i++)
        {
            if(fabs(as[i] - x) < 1e-10)
            {
                ok = 1;
                break;
            }
            if(x > as[i-1] && x < as[i])
            {
                ans = i;
                break;
            }
        }
        if(ok == 1) printf("-1\n");
        else printf("%d\n", ans*4);
    }
    return 0;
}

  

时间: 2024-11-03 21:53:46

Fractal的相关文章

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

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

POJ 1941 The Sierpinski Fractal

总时间限制: 1000ms 内存限制: 65536kB 描述 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

Fractal Streets

POJ 题意:随着越来越大的城市对现代化的不断增长的需求,人们需要新的街道设计.克里斯是负责这些设计的不幸城市规划者之一.每年的需求都在不断增加,今年他甚至被要求设计一个全新的城市.克里斯现在需要做更多的工作,因为像任何好官僚一样,他非常懒惰.鉴于这是他与大多数计算机科学家共同的性格特征,他的一个最亲密的朋友保罗实际上是计算机科学家也就不足为奇了.正是保罗提出了一个让克里斯成为同龄人英雄的好主意:分形街!通过使用希尔伯特曲线,他可以轻松填充任意大小的矩形图,只需很少的工作. 1阶的希尔伯特曲线由

POJ 2083 Fractal

问题描述 度为 1 的箱子分形是简单的: X 度为 2 的箱子分形是这样的: X X X X X 如果用 B(n-1)表示度为 n-1 的箱子分形,那么度为 n 的箱子分形可以递归地定义为如下这样: B(n-1)        B(n-1) B(n-1) B(n-1)        B(n-1) 你的任务是画出一个度为 n 的分形. 输入 输入包含若干组测试数据.数据的每行包含一个不大于 7 的正整数 n,输入的最后一行是一个负数 -1 表示输入的结束. 输出 对于每组测试数据,用 X 记号输出

Fractal Tree

尝试使用递归方式实现一棵简单的分形树,给出初始点的坐标,在此基础上根据坐标轴旋转的规则计算出子树干与根节点的坐标关系,依次递归画出左子树干和右子树干,并提供一个递归的深度用于控制画的子树的数目. 在二维坐标系中,坐标轴旋转的公式如下: In two dimensions, every rotation matrix has the following form, This rotates column vectors by means of the following matrix multip

[杂题]CSUOJ1413 Area of a Fractal

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1413 题意:题中给了图,所以不看字大概也知道  求的是第n个图形的面积. 就是找规律 递推 一类的... 先给结论: 很鬼畜的公式:     递推式是:   重点在于17和7是怎么来的. 在题图的基础上画些个框框 观察可以发现 图1中的 1*1的方格变成了图2中*的方格 其中17就是4*4+1*1 所以第二个方格的面积为前一个方格的17倍. 显然17倍了之后还不是该图形的面积,因为有(灰格子)的

Set with different fractal dimensions

Given $0<s<u<v<1$ and $s<t<v$, one can construct a Cantor set $E\subset [0,1]$ such that $\dim_H E=s, \dim_P E=t, \underline{\dim}_B E=u$ and $\overline{\dim}_B E=v$, see Sets with different dimensions in $[0,1]$,Real Analysis Exchange