UVa - 460 Overlapping Rectangles

//java solution

import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;

class Main
{
 

    public static void main (String args[])  // entry point from OS
    {
        Main myWork = new Main();  // create a dinamic instance
        myWork.Begin();            // the true entry point
    }

    void Begin()
    {
long tt=0;
Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
/*try
{
sc=new Scanner(new File("in.txt"));
}
catch(IOException e)
{
System.exit(0);
}

*/
Rectangle2D r=new Rectangle2D.Double();
Rectangle2D tm=new Rectangle2D.Double();
   long lx1,ly1,lx2,ly2;
   tt=sc.nextLong();
            for(long lkx=0;lkx<tt;lkx++)
{

lx1=sc.nextLong();
ly1=sc.nextLong();
lx2=sc.nextLong();
ly2=sc.nextLong();
r.setFrameFromDiagonal(lx1,ly2,lx2,ly1);

lx1=sc.nextLong();
ly1=sc.nextLong();
lx2=sc.nextLong();
ly2=sc.nextLong();
tm.setFrameFromDiagonal(lx1,ly2,lx2,ly1);

if(r.intersects(tm))
{
r=r.createIntersection(tm);
pr.printf("%d %d %d %d%n",(long)r.getX(),(long)r.getY(),(long)(r.getX()+r.getWidth()),(long)(r.getY()+r.getHeight()));
}
else
pr.printf("No Overlap%n");
if(lkx!=tt-1)
pr.printf("%n");
}
pr.close();
sc.close();
    }
}

No comments:

Post a Comment