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 1209. 1, 10, 100, 1000...

Where is the problem ?, write in java
Posted by carliros 18 Mar 2008 19:25
this is a part of my code, this find the value of array parameters (not contain the size).

but the judge respond wrong answer. Why?

public StringBuffer procesar(int [] array){
    StringBuffer res = new StringBuffer();
    String cad = "";
    for(int i=0;i<array.length;i++){
        int val = array[i];
        if(val == 1){
            cad = "1";
        }else {
            double dVal = cuad(1,1,(-1)*((2*val)-2));
            if(isValidate(dVal)) cad = "1";
            else cad = "0";
        }
        res.append(cad);
    }
    return res;
}
public boolean isValidate(double val){
    boolean res = false;
    double cmp = Math.round(val);
    if(val == cmp) res = true;
    return res;
}
public double cuad(int a, int b, int c){
    double res = 0;
    double x1 = ((-1)*b + Math.sqrt(b*b + ((-4)*a*c)))/(2*a);
    double x2 = ((-1)*b - Math.sqrt(b*b + ((-4)*a*c)))/(2*a);
    if(x1 > 0){
        res = x1;
    }else {
        res = x2;
    }
    return res;
}