"time limit exceeded" in java

Write here if you have problems with your Java source code

Moderator: Board moderators

"time limit exceeded" in java

Postby programmin » Tue Jun 29, 2010 12:05 am

I noticed when submitting java code to some previous contest problems, it gives "time limit exceeded". I thought maybe the code just isn't efficient enough, but then I tried a very simple, fast code that only takes input and gives bogus output. I thought it should at least change from "time limit exceeded" to "wrong answer", but this always gives "time limit exceeded":

Code: Select all
import java.util.Scanner;

public class Main {

   public static void main(String[] args) {
      int[] x = new int[4];
      int[] y = new int[4];
      Scanner sc = new Scanner(System.in);
      int entries = sc.nextInt();
      for (int i=0; i<entries; i++) {
         for (int c=0; c<4; c++) {
            x[c] = sc.nextInt();
            y[c] = sc.nextInt();
         }
         System.out.println("Case 1: Rectangle");
      }
   }
}

The problem I am trying is from the latest contest volume, "11800 - Determine the Shape".
programmin
New poster
 
Posts: 2
Joined: Mon Jun 28, 2010 11:51 pm

Re: "time limit exceeded" in java

Postby asraful.ruet » Tue Aug 31, 2010 7:38 pm

Hi ,
Someone help me !
I am getting wa !
I failed to find out error of my code .

Code: Select all
#include<stdio.h>
#include<math.h>
int main(){

    int t,i,k,j;
    int x[6],y[6],n;
    double b1,b2,b3,b4,d1,d2,d3,d4,d5,d6;

    scanf("%d",&t);

for(i=1;i<=t;i++){

    for(j=0;j<4;j++)
       scanf("%d %d",&x[j],&y[j]);

    for(j=0;j<3;j++)
     for(k=j+1;k<4;k++){
         if(y[j]>y[k]){
             n=y[j];
             y[j]=y[k];
             y[k]=n;
             n=x[j];
             x[j]=x[k];
             x[k]=n;

             }
        }

    if(x[3]>x[2]){
             n=x[2];
             x[2]=x[3];
             x[3]=n;

             n=y[2];
             y[2]=y[3];
             y[3]=n;
        }

    if(x[0]>x[1]){
             n=x[1];
             x[1]=x[0];
             x[0]=n;
             n=y[1];
             y[1]=y[0];
             y[0]=n;
        }


    b1=(double)pow((pow(x[0]-x[1],2)+pow(y[0]-y[1],2)),.5);
    b2=(double)pow((pow(x[1]-x[2],2)+pow(y[1]-y[2],2)),.5);
    b3=(double)pow((pow(x[2]-x[3],2)+pow(y[2]-y[3],2)),.5);
    b4=(double)pow((pow(x[3]-x[0],2)+pow(y[3]-y[0],2)),.5);

    d1=(double)pow((pow(x[0]-x[2],2)+pow(y[0]-y[2],2)),.5);
    d2=(double)pow((pow(x[1]-x[3],2)+pow(y[1]-y[3],2)),.5);

    d3=(double)(y[0]-y[1])/(double)(x[0]-x[1]);
    d4=(double)(y[2]-y[3])/(double)(x[2]-x[3]);

    d5=(double)(y[1]-y[2])/(double)(x[1]-x[2]);
    d6=(double)(y[3]-y[0])/(double)(x[3]-x[0]);

if(b1==b2&& b3==b4 &&b1==b3 && d1==d2)
 printf("Case %d: Square\n",i);
else if(b1==b3&&b2==b4&&b1!=b2&&d1==d2)
 printf("Case %d: Rectangle\n",i);
else if(b1==b2&& b3==b4 &&b1==b3&&d1!=d2)
 printf("Case %d: Rhombus\n",i);
else if(b1==b3&&b2==b4&&b1!=b2&&d1!=d2)
 printf("Case %d: Parallelogram\n",i);
else if((d3==d4&&d5!=d6)||(d3!=d4&&d5==d6))
 printf("Case %d: Trapezium\n",i);
else
printf("Case %d: Ordinary Quadrilateral\n",i);

}

return 0;
    }


asraful.ruet
New poster
 
Posts: 5
Joined: Wed Aug 11, 2010 8:52 am


Return to Java

Who is online

Users browsing this forum: Bing [Bot] and 1 guest