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

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

help in java
Послано ankur parashar 11 окт 2008 01:05
import java.util.Scanner;

public class Reverseroot
{
public static void main(String args[])
{
  solve();
}
public static void solve()
{
 Scanner s=new Scanner(System.in);

  while(s.hasNext())
       {
   double t=s.nextDouble();
       solve();
   double n=(double) Math.sqrt(t);
   System.out.printf("%.4f\n",n);
      }

}
}

what is wrong in my solution ..
could somebody give me the solution of this problum in C
Did you try your solution for the sample?
Послано Vladimir Yakovlev (USU) 11 окт 2008 01:51
Re: Did you try your solution for the sample?
Послано ankur parashar 11 окт 2008 03:40
i tried it on my linux machine and it is giving me right solution..may b problem due to exceed limti
i tried it using BIGDECIMAL also
here is my code but it is giving a crash ....

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Scanner;
import java.io.StreamTokenizer;

public class Reverseroot
{
public static void main(String args[])
{
  solve();
}
public static void solve()
{
 Scanner s=new Scanner(System.in);
  while(s.hasNext())
       {
    BigInteger b=new BigInteger(s.nextLine());
        solve();
  double x=Math.sqrt(b.doubleValue());
   System.out.println(BigDecimal.valueOf(x).setScale(4, RoundingMode.HALF_UP));
      }

}
}

frnds i need help
Re: help in java
Послано Davor 10 мар 2009 01:38
Put this while loop in try/catch block. I had the same problem, judge reported crash on my program. That fixed it. Seams to me that .hasNext() is the problem.

And eliminate recursion, for gods sake!! You have one stack frame for every number, and u have 256k of numbers. Its incredibly inefficient.