hihoCoder #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 找出计算的规律即可#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
int dirx[]={,,-,};
int diry[]={-,,,};
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
double n;
int num[]; int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%lf",&n);
int i;
double x=;
double y=0.5;
for(i=;;i++){
if(x>=n){
break;
}
x=x+y/2.0;
y/=2.0;
}
int w=i;
if(x==n){
printf("-1\n");
}
else{
int ans=;
for(int i=;i<w;i++){
ans+=;
}
printf("%d\n",ans);
}
}
return ;
}
hihoCoder #1234 : Fractal(数学简单题)的更多相关文章
- hihoCoder 1234 fractal
#1234 : Fractal 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specific ...
- [CF1538G] Gift Set (数学简单题)
题面 相信英文题面也很好理解 有 x \tt x x 个红糖, y \tt y y 个蓝糖.每一个礼包里面要么有 a \tt a a 个红糖+ b \tt b b 个蓝糖,要么是 a \tt a a ...
- acm.njupt 1001-1026 简单题
点击可展开上面目录 Acm.njupt 1001-1026简单题 第一页许多是简单题,每题拿出来说说,没有必要,也说不了什么. 直接贴上AC的代码.初学者一题题做,看看别人的AC代码,寻找自己的问题. ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- 天哪!毫无思绪!令人感到恐惧的数学(水题?)(TOWQs)
这道题的题目描述灰常简单,第一眼看以为是一道十分水的题目: 但是!!!(我仔细一看也没有发现这背后隐藏着可怕的真相~) 下面给出题目描述: 给出一个整数x,你可以对x进行两种操作.1.将x变成4x+3 ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
随机推荐
- 【多线程】--生产者消费者模式--Lock版本
在JDK1.5发布后,提供了Synchronized的更优解决方案:Lock 和 Condition 我们使用这些新知识,来改进例子:[多线程]--生产者消费者模式--Synchronized版本 改 ...
- Java并发框架——AQS堵塞队列管理(一)——自旋锁
我们知道一个线程在尝试获取锁失败后将被堵塞并增加等待队列中,它是一个如何的队列?又是如何管理此队列?这节聊聊CHL Node FIFO队列. 在谈到CHL Node FIFO队列之前,我们先分析这样 ...
- ThinkPHP实现跨模块调用操作方法概述
ThinkPHP实现跨模块调用操作方法概述 投稿:shichen2014 字体:[增加 减小] 类型:转载 使用 $this 可以调用当前模块内的方法,但是很多情况下经常会在当前模块中调用其他模块 ...
- js判断ie浏览器
function isIE() { //ie? if (!!window.ActiveXObject || "ActiveXObject" in window){ document ...
- sql server 删除所有表和存储过程
1.删除外键约束 DECLARE c1 cursor for select 'alter table ['+ object_name(parent_obj) + '] drop constraint ...
- 截取NSString字符串
NSString类中提供了这样三个方法用于获取子字符串: – substringFromIndex: – substringWithRange: – substringToIndex: 具体的使用见下 ...
- [转载]启用 VIM 中的 Python 自动补全及提示功能
转载: http://zhongwei-leg.iteye.com/blog/941474 周围的同事不喜欢使用 VIM 写 Python 代码的原因之一就是,VIM 不能像 Visual Studi ...
- LinearLayout的一些注意事项
1.orientation的默认值为horizontal,即从左向右排列.由于一般从上向下排列,所以必须指定orientation属性. 2.layout_gravity与gravity的区别: (1 ...
- 学习javascript中this用法的一些感悟
要想真正的掌握this,应该先要掌握javascript代码执行上下文环境的创建.转换和销毁机制:
- 欧拉(BC)
输入样例 1 1 2 1 3 2 输出样例 2 2 2f(x)打表找规律的 fx=x+1,fn(x)=x+n+1;然后用欧拉公式 #include <iostream> #include ...