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 1235. Cricket Field

1235
Posted by Meni Packeou 24 Sep 2007 10:42
import java.io.*;
import java.util.*;
  public class Criket{
   public static void main(String[] args)throws IOException{
    Scanner sc=new Scanner(System.in);
    int n=0,h=0,w=0,x=0,y=0,max=0,k=0;
    String s="",s1="";
    //.byte[][] a=new byte[1000][1000];
    boolean p;
    n=sc.nextInt();
    w=sc.nextInt();
    h=sc.nextInt();
    for(int g=0;g<n;g++){
     x=sc.nextInt();
     y=sc.nextInt();
     s+=(h-y)+"*"+x+"#";
     //a[h-y][x]=1;
    }
    max=1;x=0;y=0;
    for(int i=0;i<h;i++){
     if(i+max>=h)break;
     for(int j=0;j<w;j++){
      if(j+max>=w)break;
      p=true;k=1;
      while(p){
       if(p) k++;
       if(j+k>w){if(max<k-1){max=k-1;x=j;y=h-(i+k-1);}j=w;p=false;}
       if(i+k>h){if(max<k-1){max=k-1;x=j;y=h-(i+k-1);}j=w;p=false;}
      for(int i1=i+1;i1<i+k;i1++){
        s1="";s1+=i1+"*"+(j+k-1);
        if(s.indexOf(s1)>=0){p=false;break;}
      }
       for(int j1=j+1;j1<j+k;j1++){
        s1="";s1+=(i+k-1)+"*"+j1;
        if(s.indexOf(s1)>=0){p=false;break;}
        }
      }

      if(max<k-1){max=k-1;x=j;y=h-(i+k-1);}
      j=j+k-1;

     }
    }
    System.out.print(x+" "+y+" "+max);
   }
  }