Rezultati

Up. imeNalogaJezikRezultatČas oddaje
avokado-2018 Presek Java 100/100OK 04. okt '18 @ 20:06

Test Točke Porabljen spomin Porabljen čas Status
#1 100/100 34,555 MiB 0,000 s OK

Ocenjevani program (zgoscenka.java):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class zgoscenka {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String first = br.readLine();
		int testi = Integer.parseInt(first);
		
		for (int t = 0; t < testi; t++) {
			String line = br.readLine();
			String[] lineSplit = line.split(" ");
			
			int x1 = Integer.parseInt(lineSplit[0]);
			int y1 = Integer.parseInt(lineSplit[1]);
			int x2 = Integer.parseInt(lineSplit[2]);
			int y2 = Integer.parseInt(lineSplit[3]);
			int xk = Integer.parseInt(lineSplit[4]);
			int yk = Integer.parseInt(lineSplit[5]);
			int r = Integer.parseInt(lineSplit[6]);
			boolean stop = false;

			if (x1 <= xk && x2 >= xk) {
				if (y1 <= yk && y2 >= yk) {
					stop = true;
					System.out.println(xk + " " + yk);
				}
			}
			if (stop == false) {
				stop = checkIfInSquare(x1, x2, y1, y2, xk-r, yk);
			}
			if (stop == false) {
				stop = checkIfInSquare(x1, x2, y1, y2, xk+r, yk);
			}
			if (stop == false) {
				stop = checkIfInSquare(x1, x2, y1, y2, xk, yk+r);
			}
			if (stop == false) {
				stop = checkIfInSquare(x1, x2, y1, y2, xk, yk-r);
			}
			if (stop == false) {
				stop = checkIfInCircle (x1, y1, xk, yk, r);
			}
			if (stop == false) {
				stop = checkIfInCircle (x2, y2, xk, yk, r);
			}
			if (stop == false) {
				stop = checkIfInCircle (x1, y2, xk, yk, r);
			}
			if (stop == false) {
				stop = checkIfInCircle (x2, y1, xk, yk, r);
			}
			if(stop == false) {
				stop = checkIfOverRectangle(x1, x2, y1, y2, xk, yk, r);
			}
			if (stop == false) {
				System.out.println("Presek je prazen");
			}
			
			
			
		} 
		

		
		
	}
	
	public static boolean checkIfInCircle(int x, int y, int xk, int yk, int r) {
		double raz1 = (y-yk) * (y-yk);
		double raz2 = (x-xk) * (x-xk);
		double raz = Math.sqrt(raz2+raz1);
		if (raz <= (double)r) {
//			System.out.println(x + " " + y + " circle");
			System.out.println(x + " " + y);
			return true;
		}
		return false;
	}
	
	public static boolean checkIfInSquare(int x1, int x2, int y1, int y2, int checkx, int checky) {
		if (x1 <= checkx && x2 >= checkx) {
			if (y1 <= checky && y2 >= checky) {
//				System.out.println(checkx + " " + checky + "square");
				System.out.println(checkx + " " + checky);
				return true;
			}
		}
		return false;
	}
	
	public static boolean checkIfOverRectangle(int x1, int x2, int y1, int y2, int xk, int yk, int r) {
		if (y1 >= yk-r && y2 >= yk-r && y1 <= yk && y2 <= yk) {
			if (x1 <= xk && x2 >= xk) {
				System.out.println(xk + " " + y1);
				return true;
			}
		}
		if (y1 >= yk && y2 >= yk && y1 <= yk+r && y2 <= yk+r) {
			if (x1 <= xk && x2 >= xk) {
				System.out.println(xk + " " + y1);
				return true;
			}
		}
		if (x1 >= xk && x2 >= xk && x1 <= xk+r && x2 <= xk+r) {
			if (y1 <= yk && y2 >= yk) {
				System.out.println(x1 + " " + yk);
				return true;
			}
		}
		if (x1 >= xk-r && x2 >= xk-r && x1 <= xk && x2 <= xk) {
			if (y1 <= yk && y2 >= yk) {
				System.out.println(x1 + " " + yk);
				return true;
			}
		}
		return false;
	}

}