2015北京网络赛 H题 Fractal 找规律
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
@)1%KBO0HM418$J94$1R.jpg)
代码:
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 找规律的更多相关文章
- 2015北京网络赛A题The Cats' Feeding Spots
		
题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...
 - 2015北京网络赛 G题 Boxes bfs
		
Boxes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingonl ...
 - hihocoder 1236(2015北京网络赛 J题) 分块bitset乱搞题
		
题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...
 - 2015北京网络赛B题 Mission Impossible 6
		
借用大牛的一张图片:模拟 #include<cstdio> #include<cmath> #include<cstring> #include<algori ...
 - 2015北京网络赛 A题 The Cats' Feeding Spots 暴力
		
The Cats' Feeding Spots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acm ...
 - 2017北京网络赛 Bounce GCD加找规律
		
题目链接:http://hihocoder.com/problemset/problem/1584 题意:就是求一个小球从矩阵的左上角,跑到矩形的右下角不能重复经过的格子,小球碰到墙壁就反射. 解法: ...
 - 2015北京网络赛 Couple Trees  倍增算法
		
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
 - 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 ...
 - 2015北京网络赛 J Scores   bitset+分块
		
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
 
随机推荐
- poj2436,poj3659,poj2430
			
这两题都体现了dp的核心:状态 dp做多就发现,状态一设计出来,后面的什么都迎刃而解了(当然需要优化的还要动动脑筋): 先说比较简单的: poj2436 由题得知病毒种数<=15很小,于是我们就 ...
 - 【Grunt】
			
GRUNT The JavaScript Task Runnerhttp://gruntjs.com/ Grunt打造前端自动化工作流http://tgideas.qq.com/webplat/inf ...
 - 【转】 当程序崩溃的时候怎么办 part-1
			
转自:http://www.tairan.com/archives/1006 有这样一种情形:当我们正在快乐的致力于我们的app时,并且什么看都是无比顺利,但是突然,坑爹啊,它崩溃了.(悲伤地音乐响起 ...
 - SharePoint 2013 Pop-Up Dialogs
			
转:http://blog.csdn.net/tristan_dong/article/details/19076315 自定义弹出框 一. 项目需求: 自定义弹出框,包括弹出框的内容和样式. 说明: ...
 - Android学习系列(28)--App集成支付宝[已过期]
			
手机的在线支付,被认为是2012年最看好的功能,我个人认为这也是移动互联网较传统互联网将会大放光彩的一个功能.人人有手机,人人携带手机,花钱买东西,不再需要取钱付现,不再需要回家上网银,想买什么,扫描 ...
 - 远程调试hadoop各组件
			
远程调试对应用程序开发十分有用.例如,为不能托管开发平台的低端机器开发程序,或在专用的机器上(比如服务不能中断的 Web 服务器)调试程序.其他情况包括:运行在内存小或 CUP 性能低的设备上的 Ja ...
 - 《深入Java虚拟机学习笔记》- 第16章 控制流
			
<深入Java虚拟机学习笔记>- 第16章 控制流
 - NGINX(六)扩展
			
前言 nginx模块化设计, 添加扩展模块变得容易, 下面开发一个非常简单的扩展模块, 实现返回http请求的头部内容, 配置标记是ping_pong, 配置在NGX_HTTP_LOC_CONF中. ...
 - 欢迎来到Googny的博客
			
本博客主要分享笔者的学习知识,以及工程中遇到的技术问题. 由于笔者技术水平有限,博客不足之处在所难免,还请各位网友不吝交流,共同进步. 一起体会分享的乐趣. JavaScript 部分 该部分深入浅出 ...
 - HW6.18
			
public class Solution { public static void main(String[] args) { double[] array = {6.0, 4.4, 1.9, 2. ...