U E D R , A S I H C RSS

Birthdat Cake/하기웅

풀�

처�엔 뭔가 �기�� 방법� 없�까 ��� 많�하다가 그냥 노가다로 짜버렸다^^
그런� � 단방� Accepted가 �니 황당하다^^

ax+by=0 ��는 �� 있�때, 여기� x,y를 대입해서 ax+by>0면 -a/b�는 기울기� �선보다 위� 있는 ���는 것�고
ax+by<0면 -a/b�는 기울기� �선보다 아래� 있는 ��다.

�것� �용해서 a, b를 for문� 통해 변화 시켜가면서 위� 있는 �과 아래� 있는 �� 개수가 똑같� 때� 기울기를 찾는 방�.

소스

~cpp
#include <iostream>
using namespace std;

struct Point {
	int x;
	int y;
};

int cherry, i, j, k, a, b;
Point ch[100];

Point getLine()
{
	Point temp;
	for(i=0; i<500; i++)
	{
		for(j=1; j<=500; j++)
		{
			a=0; b=0;
			for(k=0; k<2*cherry; k++)
			{
				if((i*ch[k].x+j*ch[k].y)>0)
					a++;
				else if((i*ch[k].x+j*ch[k].y)<0)
					b++;
			}

			if(a==cherry && b==cherry)
			{
				temp.x = i;
				temp.y = j;
				return temp;
			}
		}
		for(j=-1; j>=-500; j--)
		{
			a=0; b=0;
			for(k=0; k<2*cherry; k++)
			{
				if((i*ch[k].x+j*ch[k].y)>0)
					a++;
				else if((i*ch[k].x+j*ch[k].y)<0)
					b++;
			}

			if(a==cherry && b==cherry)
			{
				temp.x = i;
				temp.y = j;
				return temp;
			}
		}
	}
}

int main()
{
	while(cin>>cherry)
	{
		if(cherry==0)
			break;
		for(i=0; i<2*cherry; i++)
			cin >> ch[i].x >> ch[i].y;
		cout << getLine().x <<" " <<getLine().y<< endl;	
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:37
Processing time 0.0032 sec