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之前 ...
随机推荐
- apache开源项目--Sirona
Apache Sirona 为 Java 应用程序提供了一个简单但可扩展的监控解决方案. apache / sirona
- 剑指Offer:连续子数组的最大和
题目: 输入一个整型数组, 数组里有正数也有负数. 数组中的一个或连续的多个整数组成一个子数组. 求所有子数组的和的最大值. 要求时间复杂度为O(n) #include <stdio.h> ...
- Android学习系列(28)--App集成支付宝[已过期]
手机的在线支付,被认为是2012年最看好的功能,我个人认为这也是移动互联网较传统互联网将会大放光彩的一个功能.人人有手机,人人携带手机,花钱买东西,不再需要取钱付现,不再需要回家上网银,想买什么,扫描 ...
- Win7下的DragEnter、DragDrop事件不触发的解决方案
Win7与原来的XP和Win2003相比,安全控制方面更严格.比如,当我们以administrator登陆XP或Win2003时,运行所有的程序即是以管理员的身份启动的.但当以administrato ...
- puppet学习:文件夹权限的问题
之前Zabbix自动部署的文件夹结构总觉得别扭,今天下午抽空调整了下.调整完后,依然是例行的测试. 在客户端执行puppet agent -t时,报错如下: Failed to generate ad ...
- sys.stdout 重定向
通俗的来说,sys.stdout的功能类似与C++里面的文件输出功能fprintf. 接下来直接入正题,让我们来看代码: >>> import sys >>> te ...
- bzoj 2815 [ZJOI2012]灾难(构造,树形DP)
[题意] 求把每个点删除后,不可达点的数目. [思路] 构造一棵“灭绝树”,要求这棵树满足如果删除根节点后则该子树内的所有结点都不可达.则答案为子树大小-1. 如何构造这棵“灭绝树”? 将原图拓扑排序 ...
- 修改首页的main里面的内容
进入后台--cms--page: 找到home的页面,进入内容,可以看到右边的显示内容为: main里面的内容如下: <div class="slideshow-container&q ...
- POJ 1005 解题报告
1.题目描述 2.解题思路 好吧,这是个水题,我的目的暂时是把poj第一页刷之,所以水题也写写吧,这个题简单数学常识而已,给定坐标(x,y),易知当圆心为(0,0)时,半圆面积为0.5*PI*(x ...
- leetcode—Palindrome 解题报告
1.题目描述 Given a string s, partition s such that every substring of the partition is a palindrome. Ret ...