UVA

/*其实这题并不难,主要是我没有理解题意,题意就是找到一个A和一个B,A和B的绝对值不超过500,使得给出的 2n 个点,刚好一半在直线上,一半在直线上

此外,当时没想到直接枚举,后来看了题解,仔细想想,这题的数据量好像真的不大,枚举确实是挺好的方法...当时怎么就不尝试呢?sigh*/

#include <iostream>
using namespace std;
struct PNode
{
	int x, y;
}P[100];
int main()
{
	int n;
	while (cin >> n)
	{
		if (!n) break;
		for (int i = 0; i < 2 * n; i++)
		cin >> P[i].x >> P[i].y;
		
		for (int A = -500; A <= 500; A++)
		for (int B = -500; B <= 500; B++)
		{
			int l = 0, r = 0;
			for (int i = 0; i < 2 * n; i++)
			{
				l += (P[i].x * A + P[i].y * B > 0);
				r += (P[i].x * A + P[i].y * B < 0);
			}
			if (l == n && r == n)
			{
				cout << A << " " << B << endl;
				A = 501; B = 501;
			} 
			
		}
	}
	return 0;
} 

原文地址:https://www.cnblogs.com/mofushaohua/p/7789520.html