Rezultati

Up. imeNalogaJezikRezultatČas oddaje
Jakub-2018 Presek C++ 100/100OK 04. okt '18 @ 19:06

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

Ocenjevani program (presek.cpp):
#include<stdio.h>

struct point{
	double x, y;
};

double razdalja(point a, point b){
	return 1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y);
}

double abs(double a){
	if(a<0) return -1*a;
	return a;
}

point s;
int r;

void calc(){
	int x1, x2, x3, y1, y2, y3;
	point p1, p2, p3, p4;
	scanf("%d %d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3, &r);
	double raz=1.0*r*r;
	s.x=x3;
	s.y=y3;
	int a;
	if(x1>x2){
		a=x1;
		x1=x2;
		x2=a;
	}
	if(y1>y2){
		a=y1;
		y1=y2;
		y2=a;
	}
	p1.x=x1;
	p1.y=y1;
	p2.x=x2;
	p2.y=y2;
	p3.x=x1;
	p3.y=y2;
	p4.x=x2;
	p4.y=y1;
	if(raz>=razdalja(s, p1)){
		printf("%.0f %.0f\n", p1.x, p1.y);
		return;
	} 
	if(raz>=razdalja(s, p2)){
		printf("%.0f %.0f\n", p2.x, p2.y);
		return;
	} 
	if(raz>=razdalja(s, p3)){
		printf("%.0f %.0f\n", p3.x, p3.y);
		return;
	}
	if(raz>=razdalja(s, p4)){
		printf("%.0f %.0f\n", p4.x, p4.y);
		return;
	} 
	if(p1.x>p2.x){ 
		p1.x+=r;
		p2.x-=r;
	}
	else{
		p1.x-=r;
		p2.x+=r;
	}
	if(p3.y>p4.y){
		p3.y+=r;
		p4.y-=r;
	}
	else{
		p3.y-=r;
		p4.y+=r;
	}
	if(((x1<=s.x && s.x<=x2) || (x1>=s.x && s.x>=x2)) && ((y1<=s.y && s.y<=y2) || (y1>=s.y && s.y>=y2))){
		printf("%.0f %.0f\n", s.x, s.y);
		return;
	}
	if(((p1.x<=s.x && s.x<=p2.x) || (p1.x>=s.x && s.x>=p2.x)) && ((p1.y<=s.y && s.y<=p2.y) || (p1.y>=s.y && s.y>=p2.y))){
		if(s.x<p3.x){
			printf("%.0f %.0f\n", p3.x, s.y);
			return;
		}
		else{
			printf("%.0f %.0f\n", p4.x, s.y);
			return;
		}
	}
	if(((p3.x<=s.x && s.x<=p4.x) || (p3.x>=s.x && s.x>=p4.x)) && ((p3.y<=s.y && s.y<=p4.y) || (p3.y>=s.y && s.y>=p4.y))){
		if(s.y<p1.y){
			printf("%.0f %.0f\n", s.x, p1.y);
			return;
		}
		else{
			printf("%.0f %.0f\n", s.x, p2.y);
			return;
		}
	}
	printf("Presek je prazen\n");
}
	
	 

int main(){
	int t;
	scanf("%d", &t);
	for(int i=0;i<t;i++){
		calc();
	}
	return 0;
}