ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1001. Обратный корень

Iqramul Islam Why Runtime error (Stack Overflow)??? [4] // Задача 1001. Обратный корень 28 окт 2018 17:22
#include <iostream>
#include <math.h>
using namespace std;

void square()
{
    long long int n;
    scanf("%lld", &n);
    if(n!=-1)
        {
            square();
            printf("%.4f\n", sqrt(n));
        }

    return;

}
int main()
{
    square();

    return 0;
}
http://acm.timus.ru/help.aspx?topic=cpp&locale=en

Visual C++ Only. In order to increase the size of a stack and to avoid its overflow when using a “deep” recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB):

#pragma comment(linker, "/STACK:16777216")
Iqramul Islam Re: Why Runtime error (Stack Overflow)??? [2] // Задача 1001. Обратный корень 30 окт 2018 00:00
sorry i don't understand .. how to set the size of the stack??? If you can explain... it might help me.....
#pragma comment(linker, "/STACK:16777216")

Put the line above in the very beginning of your program, that all.
You shouldn't touch stack size at all.

You shouldn't implement algorithms with linear depth of recursion, not more then logarithmic depth.
You shouldn't place big arrays/objects on stack.
Imagine you have 1-2K stack at all.

You should get/implement stack data structure and solve problem using it.