1 / 2
Sep 2010

Hello all, I am kind of new to java so pardon me if this is stupid. I am trying to solve this problem spoj.pl/problems/ELLIPSE/ in java but i am consistently getting error message "
runtime error (NZEC)". Could some one please tell me how to solve this.
Thank You
Mukesh Tiwari

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package determinant_recur;
import java.util.*;
import java.io.*;
import java.lang.Math.*;
/**
 *
 * @author user
 */
public class Main {
    private static long recur(long[][] M,int n)
{
    if(n==2) return M[0][0]*M[1][1]-M[0][1]*M[1][0];
    long sum=0;
    int r,c,sign=1;
    for(int i=0;i<n;i++)
    {
        long[][] tmp=new long[n-1][n-1];
        r=0;
        for(int j=1;j<n;j++)//always start with next row
        {
            c=0;
            for(int k=0;k<n;k++)
            {
                if(k==i)continue;//leave ith column
                tmp[r][c]=M[j][k];
                c++;
            }
            r++;
        }

        sum+=sign*M[0][i]*recur(tmp,n-1);
        sign*=-1;
    }
        return sum;
}
public static void main(String[] args) {

  
    while(true)
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s=null;
    int c=0;
    try
    {
        s=br.readLine().trim();
        if(s.isEmpty())break;
        s=s.replaceAll("\\s+"," ");
        String[] t=s.split(" ");
        for(int i=0;i<t.length;i++)t[i].trim();
        long[] x=new long[5];
        long[] y=new long[5];
        for(int j=0;j<10;j+=2)
        {
            
           
                x[c]= Integer.parseInt(t[j]);
                y[c++]=Integer.parseInt(t[j+1]);
               
           
        }
       // for(int i=0;i<5;i++) System.out.println(x[i]+" "+y[i]);
        long[][] M=new long[5][6];
        long[] coff=new long[6];
        double A,B,C,D,E,F;
        for(int i=0;i<5;i++)
        {
            M[i][0]=x[i]*x[i];
            M[i][1]=x[i]*y[i];
            M[i][2]=y[i]*y[i];
            M[i][3]=x[i];
            M[i][4]=y[i];
            M[i][5]=1;
        }
        int r_1,c_1;
        for(int i=0;i<6;i++)
        {
            long[][] tmp=new long[5][5];
            r_1=0;
            for(int j=0;j<5;j++)
            {
                c_1=0;
                for(int k=0;k<6;k++)
                {
                    if(k==i)continue;
                    tmp[r_1][c_1]=M[j][k];
                    c_1++;
                }
                 r_1++;
            }
           
            
            
            coff[i]=recur(tmp,5);
           // System.out.print(coff[i]+" ");
        }
        //System.out.println();
        A=coff[0]*1.0;
        B=0.5*coff[1];
        C=coff[2]*1.0;
        D=0.5*coff[3];
        E=0.5*coff[4];
        F=coff[5]*1.0;
        if(A*C<=B*B)System.out.println("IMPOSSIBLE");
        else
        {
         double Area=Math.PI*((A*E*E-2*B*D*E+C*D*D) - F*(A*C-B*B))/Math.pow((A*C-B*B),1.5);
         System.out.println(Math.abs(Area));
        }
        

    }catch (NumberFormatException e){}
    catch (EOFException e){}
    catch(IOException e){};
   }
}
}
  • created

    Sep '10
  • last reply

    Sep '10
  • 1

    reply

  • 177

    views

  • 2

    users

  • 1

    link

br should only be declared once. When you create it the next time, the stream is empty.