ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

128*1024 size of memory????
Posted by Rawnak Yazdani 5 Nov 2016 18:52
why should i declare 128*1024 size of memory for 256KB described in the problem?
my code goes here:
#include<iostream>
#include <cstdio>
#include <cmath>

double buf[128 * 1024];
int main()
{
    int i = 0;
    unsigned long long n;
    while (scanf("%llu", &n) != EOF) {
        buf[i ++] = (double)sqrt(n * 1.0);
    }
    for (; --i >= 0; ) {
        printf("%.4lf\n", buf[i]);
    }
    return 0;
}

//  why 128*1024  ?
Re: 128*1024 size of memory????
Posted by Oleg Baskakov 5 Nov 2016 18:58
Because 256kb means there's at most 128kb of digits and 128kb of spaces?
Re: 128*1024 size of memory????
Posted by Rawnak Yazdani 5 Nov 2016 19:13
Here the array size is 128*1024 and it is double. So doesn't the array hold 128*1024*8 KB of memory(8 bytes for each element) ?
Re: 128*1024 size of memory????
Posted by Oleg Baskakov 5 Nov 2016 20:22
Well you don't necessarily need double, you may use long long int for keeping numbers.
Of course, it's 8 bytes either way, but you just don't know whether your numbers are going to be a few huge ones, or a ton of 1-digit ones, so you just have to be on a safe side.