#1234 : 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

重复1000次是个幌子,根本没有那么极端的数据,实际上重复到50多次就全是0.500000……了(用double)

所以不用纠结循环500还是循环1000,更不用纠结是501还是499.只要循环50就够了。

#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 1234 int n,flag,b[N];
double x,a[N];
const double eps = 1e-; void init()
{
a[] = 0.0;
b[] = ;
double f = 1.0 / ;
for(int i = ; i <= ; i++)
{
a[i] += a[i-] + f;
b[i] = b[i-] + ;
f = f / ;
}
// for(int i = 1; i <= 55; i++)
// {
// printf("%.60f\n ", a[i]);
// }
} int main()
{
init();
int T;cin>>T;
while(T--)
{
scanf("%lf", &x);
if(x > 0.5) x = - x;
for(int i = ; i <= ; i++)
{
if(fabs(x - a[i]) < eps)
{
printf("-1\n");
break;
}
else if(x < a[i] && x > a[i-])
{
printf("%d\n", b[i]);
break;
}
}
} return ;
} /*
3
0.375
0.001
0.478 */

hihoCoder 1234 fractal的更多相关文章

  1. hihoCoder #1234 : Fractal(数学简单题)

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specifically, the logo i ...

  2. 2015北京网络赛 H题 Fractal 找规律

    Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...

  3. ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)

    hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB   描述 There is a strange storehouse in PKU. In this ...

  4. hihocoder -1121-二分图的判定

    hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...

  5. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

  6. hihoCoder太阁最新面经算法竞赛15

    hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...

  7. 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II

    http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...

  8. 【hihocoder#1413】Rikka with String 后缀自动机 + 差分

    搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...

  9. 【hihoCoder】1148:2月29日

    问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...

随机推荐

  1. JQuery中xxx is not a function或者can not find $

    在项目中,遇到以上两个错误,反复折腾了好久,js代码写得没有问题,jquery的文件也引入了,就是反复的报告错误,xxx is not a function.如图: 就是这样的错误,shake is ...

  2. jQuery DOM 互转

    jQuery对象与DOM对象是不一样的 通过一个简单的例子,简单区分下jQuery对象与DOM对象: <p id=”imooc”></p> 我们要获取页面上这个id为imooc ...

  3. Java-确定字符串是否包含子字符串

    利用String自带的函数和正则来实现 package com.tj; public class MyClass implements Cloneable { public static void m ...

  4. 【工具】Homebrew的安装及使用

    Homebrew官网:http://brew.sh/index_zh-cn.html Homebrew是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,相当于linux下的a ...

  5. 【LeetCode】Pancake Sorting(煎饼排序)

    这道题是LeetCode里的第969道题. 题目要求: 给定数组 A,我们可以对其进行煎饼翻转:我们选择一些正整数 k <= A.length,然后反转 A 的前 k 个元素的顺序.我们要执行零 ...

  6. 【Luogu】P1613跑路(倍增+Floyd)

    题目链接在此 其实我看到这道题一点想法都没有 设f[i][j][k]表示用2i秒能不能从j走到k.如果可以,那j到k就可以一秒走到,它们的路径长度就是1.方程为f[i][j][k]=f[i-1][j] ...

  7. 深入了解类加载过程及Java程序执行顺序

    前言 在Java中,静态 Static关键字使用十分常见 本文全面 & 详细解析静态 Static关键字,希望你们会喜欢 目录 1. 定义 一种 表示静态属性的 关键字 / 修饰符 2. 作用 ...

  8. BZOJ 3309 DZY Loves Math ——莫比乌斯反演

    枚举$d=gcd(i,j)$ 然后大力反演 ——来自Popoqqq的博客. 然后大力讨论后面的函数的意义即可. http://blog.csdn.net/popoqqq/article/details ...

  9. springmvc简单的xml文件配置步骤

    1.配置web.xml的servlet标签,在此标签中配置服务器配置文件 2.配置web.xml的servlet-mapping标签 3.配置application.xml的自动扫描包的位置 4.配置 ...

  10. kail Linux 安装Parallels Tools

    网上好多都是Parallels8的 针对Parallels 9 的还真不好找..... 自己捣鼓了一阵 终于可以安装了,但还是有错误,因为公司网络太不给力....回家再测试吧 1.在桌面新建一个文件夹 ...