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
题意: 在一个坐标系里有如图图像,问当直线x=k与图像交点有多少,如果是无数的话输出-1
 #include <iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm> using namespace std; #define N 1100
#define INF 0x3f3f3f3f int main()
{
int t;
double x;
scanf("%d", &t);
double c = 0.5;
double a[N] = {};
int b[N] = {};
for(int i = ; i < ; i++)
{
a[i] = c/ + a[i-];
b[i] = b[i-] + ;
c /= ;
}
while(t--)
{
scanf("%lf", &x);
for(int i = ; i < ; i++)
{
if(fabs(a[i]-x) < 0.00000000000001)
{
printf("-1\n");
break;
}
else if(x < a[i])
{
printf("%d\n", b[i]);
break;
}
}
}
return ;
}

最新文章

  1. 大型网站演化(转载 http://homeway.me/2014/12/10/think-about-distributed-clusters/)
  2. 编辑并列DIV
  3. [CentOS 6.5 X64]讓firefox java plugin 啟動
  4. 分分钟解决iOS开发中App启动广告的功能
  5. java 数组插入元素
  6. embedded dylibs/frameworks are only supported on iOS 8.0 and later 错误解决
  7. String.Join的实现
  8. 轻松几句搞定【Javascript中的this指向】问题
  9. Linux端口被占用的解决(附Python专版)
  10. C#中关键字 &#39;User&#39; 附近有语法错误
  11. web前端面试题题目
  12. 餐饮ERP相关问题FAQ
  13. Starting httpd: httpd: Could not reliably determine the server&#39;s fully qualified domain name
  14. Golang中使用kafka
  15. js中的eval函数另一种实现
  16. 项目总结12:bootstrap-select下拉框模糊搜索
  17. 【NumberValidators】工商营业执照号码和统一社会信用代码验证
  18. Nginx控制客户端请求的速率
  19. Quartus II 安装教程—FPGA入门教程【钛白Logic】
  20. Linux epoll版定时器

热门文章

  1. Win10.去掉任务栏缩略图(just4explorer)
  2. 毕业之后de经历
  3. 二维数组中的查找-剑指 offerP38
  4. 移动端自动化测试之Appium的工作原理学习
  5. 【洛谷p1981】表达式求值
  6. linux驱动模型——platform(1)
  7. pip源地址
  8. SQL语句-exec执行
  9. 关于discuz论坛邮箱配置
  10. [BJWC2010]严格次小生成树(LCA,最小生成树)