Sunday, June 7, 2015

UVa 270 - Lining Up

// UVa 270 - Lining Up

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int x[700], y[700];

bool alined(int i, int j, int k) {
	int x1 = x[j] - x[i];
	int x2 = x[k] - x[i];
	int y1 = y[j] - y[i];
	int y2 = y[k] - y[i];
	return x1 * y2 - x2 * y1 == 0;
}

int main() {

	int cases;
	cin >> cases;
	string line;
	getline(cin, line);
	getline(cin, line);
	for (; cases; cases--) {
		int n = 0;
		getline(cin, line);
		while (line.length() > 0) {
			istringstream strm(line);
			strm >> x[n] >> y[n];
			getline(cin, line);
			n++;
		}
		int sol = 2;
		for (int i = 0; i < n - 2; i++) {
			for (int j = i + 1; j < n - 1; j++) {
				int s = 2;
				for (int k = j + 1; k < n; k++)
					if (alined(i, j, k))
						s++;
				if (s > sol)
					sol = s;
			}
		}
		cout << sol << endl;
		if (cases > 1)
			cout << endl;
	}

	return 0;
}

No comments:

Post a Comment