Square Large Array (c + +)

Source: Internet
Author: User

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 + +)

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.