Hihocoder #1234: Fractal (Math simple problem)

Source: Internet
Author: User
Tags float number

Time limit: 1000ms single point time limit: 1000ms memory limit: 256MB 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 (All), 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 and then square ai+1bi+1ci+1di+1 are generated by linking the midpoints of Aibi, Bici, Cidi and Diai successively.

4. Repeat step three.

Now the designer decides-add a vertical line x=k-to-this logo (0<= K < 0.5, and for K, there'll be is at most 8 di Gits 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 < s), indicating the number of test cases.

Then T-lines follow, each describing a-test case. Each line contains a float number k, meaning that is 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 is infinity common points, print-1.

Sample input
30.3750.0010.478
Sample output
-1420


Find out the rules of calculation
1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> -#include <stack> the using namespacestd; - intdirx[]={0,0,-1,1}; - intdiry[]={-1,1,0,0}; - #definePI ACOs (-1.0) + #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) + #definell Long Long A #defineEPS 1e-10 at #defineMOD 1000000007 - #defineN 1000000 - #defineINF 1e12 - DoubleN; - intnum[100000]; -  in intMain () - { to     intT; +scanf"%d",&t); -      while(t--){ thescanf"%LF",&n); *         inti; $         Doublex=0;Panax Notoginseng         Doubley=0.5; -          for(i=0;; i++){ the             if(x>=N) { +                  Break; A             } thex=x+y/2.0; +Y/=2.0; -         } $         intw=i; $         if(x==N) { -printf"-1\n"); -         } the         Else{ -             intans=0;Wuyi              for(intI=0; i<w;i++){ theans+=4; -             } Wuprintf"%d\n", ans); -         } About     } $     return 0; -}
View Code

Hihocoder #1234: Fractal (Math simple problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.