#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.

样例输入
  1. 3
  2. 0.375
  3. 0.001
  4. 0.478
样例输出
  1. -1
  2. 4
  3. 20

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

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

  1. #include<math.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<string>
  5. #include<iostream>
  6. #include<algorithm>
  7. using namespace std;
  8. #define N 1234
  9.  
  10. int n,flag,b[N];
  11. double x,a[N];
  12. const double eps = 1e-;
  13.  
  14. void init()
  15. {
  16. a[] = 0.0;
  17. b[] = ;
  18. double f = 1.0 / ;
  19. for(int i = ; i <= ; i++)
  20. {
  21. a[i] += a[i-] + f;
  22. b[i] = b[i-] + ;
  23. f = f / ;
  24. }
  25. // for(int i = 1; i <= 55; i++)
  26. // {
  27. // printf("%.60f\n ", a[i]);
  28. // }
  29. }
  30.  
  31. int main()
  32. {
  33. init();
  34. int T;cin>>T;
  35. while(T--)
  36. {
  37. scanf("%lf", &x);
  38. if(x > 0.5) x = - x;
  39. for(int i = ; i <= ; i++)
  40. {
  41. if(fabs(x - a[i]) < eps)
  42. {
  43. printf("-1\n");
  44. break;
  45. }
  46. else if(x < a[i] && x > a[i-])
  47. {
  48. printf("%d\n", b[i]);
  49. break;
  50. }
  51. }
  52. }
  53.  
  54. return ;
  55. }
  56.  
  57. /*
  58. 3
  59. 0.375
  60. 0.001
  61. 0.478
  62.  
  63. */

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. python基础学习笔记——文件操作

    文件操作 初始文件操作 使用Python来读写文件是非常简单的操作,我们使用open()函数来打开一个文件,获取到文件句柄,然后通过文件句柄就可以进行各种各样的操作了 根据打开方式的不同能够执行的操作 ...

  2. unittest的discover方法使用

    使用unittest进行测试,如果是需要实现上百个测试用例,把它们全部写在一个test.py文件中,文件会越来越臃肿,后期维护页麻烦.此时可以将这些用例按照测试功能进行拆分,分散到不同的测试文件中. ...

  3. 修复Centos7双系统引导

    1.进入CentOS系统 2.命令行输入 vi /boot/grub2/grub.cfg 3.在文件空白处添加下列代码 menuentry 'Windows 7'{ insmod part_msdos ...

  4. vim 第三章 插入模式

    vim 第三章  插入模式 在普通模式下可以删除  复制   及粘贴的命令    在插入模式下也存在以中方便快捷的方式    能够粘贴寄存器中文本   两种方式来插入键盘上不存在的非常用字符 替换模式 ...

  5. 【LeetCode】Combination Sum II(组合总和 II)

    这道题是LeetCode里的第40道题. 题目要求: 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. can ...

  6. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  7. hlg 1580 tell me the length

    智力题,观察上一行,有几个数字. 比如,S[1]=1; S[2]=11; S[3]=21; S[4]=1211; 这样就可以观察出来,序列一是1个1 --->  S[2] = 11 ; 序列二是 ...

  8. POJ-2594 Treasure Exploration,floyd+最小路径覆盖!

                                                 Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...

  9. php排序介绍_冒泡排序_选择排序法_插入排序法_快速排序法

    这里我们介绍一些常用的排序方法,排序是一个程序员的基本功,所谓排序就是对一组数据,按照某个顺序排列的过程. 充效率看 冒泡排序法<选择排序法<插入排序法 排序分两大类: 内部排序法 交换式 ...

  10. php 学习随笔

    ---恢复内容开始--- round进行格式化数值(进位规则遵守“四舍六入五双”,即前一位是奇数,则进一,前一位是偶数则舍入,因此,rount(1.5)=2,round(2.5)=2,round(0. ...