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

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

why crash #6
Послано Alireza_Keshmiri 11 янв 2009 19:42
I got Crash on test #6... is anyone can help me?

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Test1001 {
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(
                new InputStreamReader(System.in)));
        Run(in);
    }

    static void Run(StreamTokenizer in) throws IOException {
        double num = 0;

        while (in.nextToken() != StreamTokenizer.TT_EOF)
            if (in.ttype == StreamTokenizer.TT_NUMBER) {

                num = (num < 0) ? -in.nval : in.nval;

                Run(in);
                System.out.println(String.format("%.4f", Math.sqrt(num)));
            }
    }
}
Re: why crash #6
Послано Fyodor Menshikov 11 янв 2009 21:03
http://acm.timus.ru/help.aspx?topic=java

Under "Stack size" title there is template of program that may use big stack.
Re: why crash #6
Послано Alireza_Keshmiri 11 янв 2009 22:23
thank you it works.
No more crash but "Time limit exceeded" on test #9...

Any Idea?

import java.io.*;

public class Test1001 implements Runnable {
    public static void main(String[] args) throws IOException {
        new Thread(new Test1001()).start();
    }

    public void run() {
        try {
            StreamTokenizer in = new StreamTokenizer(new BufferedReader(
                    new InputStreamReader(System.in)));

            Run(in);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    static void Run(StreamTokenizer in) throws IOException {
        double num = 0;

        while (in.nextToken() != StreamTokenizer.TT_EOF)
            if (in.ttype == StreamTokenizer.TT_NUMBER) {

                num = (num < 0) ? -in.nval : in.nval;

                Run(in);
                System.out.println(String.format("%.4f", Math.sqrt(num)));
            }
    }
}
Re: why crash #6
Послано Fyodor Menshikov 12 янв 2009 22:58
Alireza_Keshmiri писал(a) 11 января 2009 22:23
Any Idea?

Do not try to solve problems from the problemset in order of their numbers. Solve problems that were solved by more authors than others. Maybe sometime you will obtain experience to solve and this problem.

Here is the start of my rating of Timus problems complexity:
1409
1000
1293
1493
1496
1404
1349
1457
1197
1502
1068
1319
1264
1545
1313
1567
1327
1510
1581
1585
1446
1563
1370
1263
1209
1083
1617
1243
1607
1402
1413
1082
1506
1601
1025
1573
1225
1196
1290
1582
1352
1330
1224
1636
1433
1079
1576
1515
1149
1005
1131
1194
1336
1110
1638
1139
1639
1491
1161
1214
1084
1009
1228
1206
1353
1612
1296
1044
1283
1086
1180
1490
1572
1014
1423
1146
1297
1385
1020
1406
1100
1497
1226
1120
1222
1335
1431
1219
1022
1295
1203
1142
1642
1192
1026
1073
1644
1354
1551
1021
Re: why crash #6
Послано Alireza_Keshmiri 13 янв 2009 21:01
Hi again and thank you for advice so I will follow your list but please let me know if you find out the problem of limitation.. I am VB and C# advanced developer and I am going to learn Java as a 3rd language. so it will be interested to know WHY?

best wishes for you
Re: why crash #6
Послано Fyodor Menshikov 14 янв 2009 01:19
Alireza_Keshmiri писал(a) 13 января 2009 21:01
please let me know if you find out the problem of limitation..

I tried to change your solution to overcome TLE9. And I've failed. I think that the only way to overcome TLE in this problem is to remove recursion. Use two loops (reading and writing) and explicit storage.