| square Large Array |
| difficulty level: D; run time limit: 1000ms; operating space limit: 256000KB; code length limit: 2000000B |
| Question Description |
|
|
| input |
first row A positive integer n represents the number of queries.
The next n rows with a decimal number of no more than eight bits per row represent a set of queries. The |
| output |
| outputs a total of n rows, representing the answer for each query, and outputs "1" if there are countless intersections. |
| Input Example |
3
0.375
0.001
0.478 |
| Output Example |
-1
4
|
|
100% data satisfies 1<=n<2*1000,0<k<0.5. Choose from tyvj
Math puzzles ... |
#include <iostream>
using namespace Std;
Double a[2004],a[2004];
int b[2004];
int n;
Double k;
void Init ()
{
a[1]=0.25;
a[1]=0.25;
a[0]=0;
b[0]=4;
for (int i=2;i<=2001;i++) {a[i]= (double) A[i-1]/2;}
for (int i=2;i<=2001;i++) {a[i]= (double) (a[i-1]+ (double) a[i]);}
for (int i=1;i<=2001;i++) b[i]=b[i-1]+4;
}
void ans (double k)
{
for (int i=1;i<=2001;i++) if (a[i]==k) {cout<< "-1" <<endl;return;}
for (int i=1;i<=2001;i++) if (a[i-1]<k&&a[i]>k) {Cout<<b[i-1]<<endl;return;}
}
int main ()
{
Init ();
cin>>n;
while (n--)
{
cin>>k;
Ans (k);
}
}
Square Large Array (c + +)