Topic Links:
http://hihocoder.com/problemset/problem/1234
Problem Solving Ideas:
Main topic:
With A0 (0,0), B0 (0,1), C0 (total), D0 (1,0) Four points of the square, each take the edge a0b0, B0C0, c0d0, d0a0 midpoint connected, can get a new square, press
This operation 1000 times, you can get with the title given to the picture, now in X for 0~0.5 between a vertical x=k, ask you the vertical line and the logo has a few intersections, when there are infinite
Output "-1" directly at the intersection of
Algorithm idea:
A closer look will reveal that the horizontal axis of each vertical edge is equal to (the horizontal axis of the previous vertical edge +0.5)/2, and then according to: if the vertical line is coincident with the edge of the small square,
The output is "1"; the other, the farther inward, each passing through a square with an edge perpendicular to the x-axis, adds 4 intersections. Finally, it can be solved by lower_bound ...
AC Code:
#include <iostream>
#include <cstdio>
using namespace std;
Double a[1005];
void Init () {
double x = 0.5;
for (int i = 0; I <=, i++) {
a[i] = 0.5-x;
x *= 0.5;
}
}
int main () {
int T;
Init ();
scanf ("%d", &t);
while (t--) {
double K;
scanf ("%lf", &k);
int pos = Lower_bound (a,a+505,k)-A;
if (a[pos] = = k)
puts ("-1");
else
printf ("%d\n", 4*pos);
}
return 0;
}