Fractal

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://hihocoder.com/contest/acmicpc2015beijingonline/problem/8

Description

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.

Input

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.

Output

For each test case, print a line containing one integer indicating the answer. If there are infinity common points, print -1.

Sample Input

3
0.375
0.001
0.478

Sample Output

-1
4
20

HINT

题意

给你一个正方形,然后下一个正方形是这个正方形的边上的终点连起来的,然后接着这样构造下去

然后划一条线,问你经过了多少个点

题解:

找规律题,怕爆精度,所以用的java

代码:

import java.io.*;
import java.math.*;
import java.util.*; public class Main
{
static BigDecimal a[] = new BigDecimal[];
public static void main(String argv[]) throws Exception
{
Scanner cin = new Scanner(System.in);
a[] = BigDecimal.valueOf();
BigDecimal x = BigDecimal.valueOf(0.5);
BigDecimal kk = BigDecimal.valueOf(0.5);
BigDecimal y;
for(int i = ; i <= ; ++ i)
{
x = x.multiply(kk);
a[i] = a[i-].add(x);
}
int Case = cin.nextInt();
while(Case != )
{
y = cin.nextBigDecimal();
int L = , R = ;
while(L <= R)
{
int mid = L + (R-L) / ;
int result = a[mid].compareTo(y);
if(result == ) R = mid - ;
else if(result == -) L = mid + ;
else
{
L = mid;
break;
}
}
if(a[L].compareTo(y) == ) System.out.println(-);
else System.out.println(L*);
Case--;
}
}
}

2015北京网络赛 H题 Fractal 找规律的更多相关文章

  1. 2015北京网络赛A题The Cats' Feeding Spots

    题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...

  2. 2015北京网络赛 G题 Boxes bfs

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

  3. hihocoder 1236(2015北京网络赛 J题) 分块bitset乱搞题

    题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...

  4. 2015北京网络赛B题 Mission Impossible 6

    借用大牛的一张图片:模拟 #include<cstdio> #include<cmath> #include<cstring> #include<algori ...

  5. 2015北京网络赛 A题 The Cats' Feeding Spots 暴力

    The Cats' Feeding Spots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acm ...

  6. 2017北京网络赛 Bounce GCD加找规律

    题目链接:http://hihocoder.com/problemset/problem/1584 题意:就是求一个小球从矩阵的左上角,跑到矩形的右下角不能重复经过的格子,小球碰到墙壁就反射. 解法: ...

  7. 2015北京网络赛 Couple Trees 倍增算法

    2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道.  解法来自 q ...

  8. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...

  9. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

随机推荐

  1. hibernate实体的几种状态:

    hibernate实体的几种状态: 实体的生命周期中,实体主要经过瞬时(Transient),托管(Attatched或Managed),游离(Detached)和销毁(Removed)四个状态. 瞬 ...

  2. struts2关于package 的 namespace

    namespace决定了action的访问路径,默认为"",可以接收所有路径的actionnamespace可以写为/ ,或者/xxx,或者/xxx/yyy,对应的action访问 ...

  3. 函数fsp_alloc_seg_inode_page

    分配一个新的inode page /**********************************************************************//** Allocat ...

  4. 十个免费的Web压力测试工具

    两天,jnj在本站发布了<如何在低速率网络中测试 Web 应用>,那是测试网络不好的情况.而下面是十个免费的可以用来进行Web的负载/压力测试的工具,这样,你就可以知道你的服务器以及你的W ...

  5. 【转】Android AlertDialog 点击对话框外部区域不关闭的设置

    原文网址:http://blog.sina.com.cn/s/blog_8f1c79dd0101a63u.html 在Android开发中,常常需要调用对话框,但会遇到这样一种情况,在显示对话框的时候 ...

  6. ASP.Net MVC_DotNetZip简单使用方法,解决文件压缩的问题[转]

    准备工作: 在vs工具栏中找到NuGet   下载DotNetZip   现在就可以使用DotNetZip强大的类库了,在这里我给出一些简单的使用. ? 1 2 3 4 5 6 7 8 9 10 11 ...

  7. svn文件清理Bat脚本

    @echo On@Rem C:\Users\caoxiancc\Desktop\Ueditor-thinkphp-master\Ueditor --svn跟路径@PROMPT [Com] @for / ...

  8. Navicat通过云主机内网连接阿里云RDS

    背景 公司为了安全起见,RDS设置只允许阿里云主机的内网端可以访问.这就意味,如果要操作RDS就需要连接到云主机上之后通过mysql shell操作.操作起来很复杂麻烦,今天看同事用Navicat f ...

  9. Mysql的函数使用方法

    今天有点临时需求要计算一张表的结果,不想写代码,想到了mysql的自定义函数.碰到了很多问题,为了方便一下使用,在此记录一下. 需求:一张表中,有比分,需要查询出比赛id和比赛结果. 分析:     ...

  10. leetcode@ [30/76] Substring with Concatenation of All Words & Minimum Window Substring (Hashtable, Two Pointers)

    https://leetcode.com/problems/substring-with-concatenation-of-all-words/ You are given a string, s, ...