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. Python图

    从一位前辈的博客看到了一张图,先转过来,稍后再细看

  2. [原]Unity3D深入浅出 - 新版动画系统(Mecanim)

    Mecanim概述: Mecanim是Unity提供第一个丰富而复杂的动画系统,提供了: 针对人形角色的简易的工作流和动画创建能力 Retargeting(运动重定向)功能,即把动画从一个角色模型应用 ...

  3. PHP Fileinfo组件越界内存破坏漏洞

    漏洞版本: PHP PHP 5.x 漏洞描述: BUGTRAQ ID: 66002 CVE(CAN) ID: CVE-2014-2270 PHP是一种HTML内嵌式的语言. PHP的file程序在解析 ...

  4. [2015编程之美] 第一场A

    #1156 : 彩色的树 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵n个节点的树,节点编号为1, 2, …, n.树中有n - 1条边,任意两个节点间恰好有一 ...

  5. hdu 2844 Coins

    Coins Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted S ...

  6. SharePoint Security and Permission System Overview

    转:http://www.sharepointblues.com/2010/09/01/sharepoint-security-and-permission-system-overview/ Shar ...

  7. spring+mybatis 多数据源整合

    <!-- 数据源配置 -->   <bean id="ds1" class="org.apache.commons.dbcp.BasicDataSour ...

  8. Selenium2Library中的Get Alert Message

    今天在处理页面的弹出框(alert)时,发现Get Alert Message 并不如字面意思这么简单 函数说明如下: 很明了:(1)返回alert 的text (2)如果没有alert,则该keyw ...

  9. python 网络编程(一)---基础

    1.理解TCP 1.1 寻址 首先任何基于TCP/IP的网络,每台机器都有唯一的IP地址,只需要知道接受者机器的IP地址,信息就可以传送过去. 其次,TCP通过使用端口号来知道机器究竟是哪个程序应该接 ...

  10. 分享两个模拟get和post方法的工具类,让应用能够与服务器进行数据交互

    很久没有码字了,今天跟大家分享一个模拟get和post方法的工具类,在安卓应用中很多都需要跟服务器进行数据交互,这需要两方面的配合,首先服务器端会给应用提供一些数据交互的接口,可是怎样在应用中去调用呢 ...