uva 10167 - Birthday Cake

简单枚举法不解释。

 

#include<stdio.h>

#define MAX 105

int cherry[MAX][2];
int n;

void search() {
	int i, j, k;
	int oneHalf;
	int theOther;
	int error;
	for (i = -500; i <= 500; i++)
		for (j = -500; j <= 500; j++) {
			oneHalf = theOther = 0;
			error = 0;
			for (k = 0; k < 2 * n; k++) {
				if (i * cherry[k][0] + j * cherry[k][1] < 0)
					oneHalf++;
				else if (i * cherry[k][0] + j * cherry[k][1] > 0)
					theOther++;
				else {
					error = 1;
					break;
				}
			}

			if (!error && oneHalf == theOther) {
				printf("%d %d\n", i, j);
				return;
			}
		}

}

int main() {

	while (scanf("%d", &n) != EOF) {
		if (n == 0)
			break;
		int k;
		for (k = 0; k < 2 * n; k++) {
			scanf("%d%d", &cherry[k][0], &cherry[k][1]);
		}

		search();
	}

	return 0;
}

 

你可能感兴趣的:(birt)