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