hihoCoder 1234 fractal
#1234 : 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
重复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的更多相关文章
- hihoCoder #1234 : Fractal(数学简单题)
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specifically, the logo i ...
- 2015北京网络赛 H题 Fractal 找规律
Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...
- ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)
hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strange storehouse in PKU. In this ...
- hihocoder -1121-二分图的判定
hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...
- Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...
- hihoCoder太阁最新面经算法竞赛15
hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...
- 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II
http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...
- 【hihocoder#1413】Rikka with String 后缀自动机 + 差分
搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...
- 【hihoCoder】1148:2月29日
问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...
随机推荐
- gg mirror
https://gufen.ga/ (无广告,原guso.ml,ggso.ga,guge.ga) https://a.aiguso.tk (无广告,体验良好) https://a.freedo.gq/ ...
- Knockout v3.4.0 中文版教程-4-通过监控数组工作
2.通过监控数组工作 1. 监控数组 如果你想检测或者响应一个对象的改变,你用observables.如果你想检测和响应一个集合的改变,使用observableArray.这个在很多情况下都非常有用, ...
- PYDay1-洗剑
学习语言的阶段: 第一阶段:所有东西都是新的::一个月 第二阶段:开始懂一些::一个月 第三阶段:感觉自己是不可战胜的:第三~第四个月 第四阶段:突然感觉什么都不知道,开发是无止境的::培训阶段不会遇 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ-3261 Milk Patterns,后缀数组+二分。。
Milk Patterns 题意:求可重叠的至少重复出现k次的最长的字串长. 这题的做法和上一题 ...
- ORACLE查询字段中含有空格的数据
SELECT * FROM T_NAME WHERE REGEXP_LIKE(COLNAME, '( )+'); SELECT * FROM T_NAME WHERE length(COLNAME) ...
- HDU 5352 MZL's City (2015 Multi-University Training Contest 5)
题目大意: 一个地方的点和道路在M年前全部被破坏,每年可以有三个操作, 1.把与一个点X一个联通块内的一些点重建,2.连一条边,3.地震震坏一些边,每年最多能重建K个城市,问最多能建多少城市,并输出操 ...
- cf299C Weird Game
Weird Game Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, ...
- linux 安装软件出现/tmp 磁盘不足时 解决方案
1.解决办法 mkdir 文件夹——你可以使用的文件夹 比如说 mkdir /mnt/tmp 然后只要export TMPDIR=/mnt/tmp 这样就不会出现 tmp文件夹不够用的情况
- 定时任务-Quartz
Quartz Quartz w3c教程 参考:https://blog.csdn.net/lkl_csdn/article/details/73613033 Quartz 的使用 https://ww ...