답안 #684600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684600 2023-01-22T00:37:21 Z GusterGoose27 Paralelogrami (COCI17_paralelogrami) C++11
28 / 140
1 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 400;
pii points[MAXN];
int n;

pii operator+(pii a, pii b) {
	return pii(a.first+b.first, a.second+b.second);
}

pii operator-(pii a, pii b) {
	return pii(a.first-b.first, a.second-b.second);
}

int operator*(pii a, pii b) {
	return a.first*b.second-a.second*b.first;
}

pii operator*(int a, pii b) {
	return pii(a*b.first, a*b.second);
}

class action {
public:
	int a, b, c;
	action(int a, int b, int c) : a(a), b(b), c(c) {}
};

vector<action> actions;

void make_action(int a, int b, int c) {
	actions.push_back(action(a, b, c));
	points[c] = points[a]+points[b]-points[c];
}

void reflect(int a, int b, int c) { // reflect triangle about c
	make_action(c, b, a);
	make_action(c, a, b);
	make_action(c, b, a);
}

bool x_good = 0, y_good = 0;

bool good(int x, int y, int z) {
	pii a = 2*points[z]-points[x]-points[y];
	if (a.first*a.second >= 0) {
		if (a.first != 0 && !x_good) {
			if (a.first < 0) {
				make_action(x, y, z);
			}
			x_good = 1;
			return 1;
		}
		if (a.second != 0 && !y_good) {
			if (a.second < 0) {
				make_action(x, y, z);
			}
			y_good = 1;
			return 1;
		}
	}
	return 0;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> points[i].first >> points[i].second;
	}
	int a = 0, b = 1, c = -1;
	for (int i = 2; i < n; i++) {
		if ((points[i]-points[a])*(points[i]-points[b]) != 0) {
			c = i;
			break;
		}
	}
	if (c == -1) {
		cout << "-1\n";
		return 0;
	}
	for (int i = 0; i < 2; i++) {
		if (good(c, b, a)) {
			swap(a, c);
		}
		else if (good(c, a, b)) {
			swap(b, c);
		}
		else if (good(a, b, c)) { // do nothing

		}
		else {
			assert(false);
		}
		for (int j = 0; j < 30; j++) {
			reflect(a, b, c);
			make_action(a, b, c);
		}
	}
	for (int i = 0; i < n; i++) {
		if (i == a || i == b || i == c) continue;
		make_action(a, b, i);
	}
	cout << actions.size() << "\n";
	for (int i = 0; i < actions.size(); i++) {
		action m = actions[i];
		cout << (1+m.a) << " " << (1+m.b) << " " << (1+m.c) << "\n";
	}
}

Compilation message

paralelogrami.cpp: In function 'int main()':
paralelogrami.cpp:109:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<action>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |  for (int i = 0; i < actions.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -