Rezultati

Up. imeNalogaJezikRezultatČas oddaje
rektifikatorji-2018 Zaletavanje C++ 100/100OK 19. apr '18 @ 19:52

Test Točke Porabljen spomin Porabljen čas Status
#1 14/14 3,172 MiB 0,000 s OK
#2 14/14 3,172 MiB 0,000 s OK
#3 14/14 3,168 MiB 0,000 s OK
#4 14/14 3,039 MiB 0,001 s OK
#5 14/14 3,039 MiB 0,001 s OK
#6 15/15 3,117 MiB 0,007 s OK
#7 15/15 3,176 MiB 0,050 s OK

Ocenjevani program (Source.cpp):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3

int w = 0, h = 0;

struct avto {
	public:
		avto() : moving(true) {}
		int x, y, dir;
		bool moving;
		void move(int t) {
			switch (dir) {
			case UP:
				if (y + t > h) {
					y = h;
					moving = false;
				} else
					y += t;
				break;
			case RIGHT:
				if (x + t > w) {
					x = w;
					moving = false;
				} else
					x += t;
				break;
			}
		}
};

int main() {
	int n;
	cin >> n >> w >> h;
	vector<avto> avti(n);
	char c;
	for (int i = 0; i < n; ++i) {
		cin >> c;
		if (c == 'G') avti[i].dir = UP;
		else if (c == 'D') avti[i].dir = RIGHT;
		cin >> avti[i].x >> avti[i].y;
	}

	int m = n;
	int minTime = max(w, h);
	vector<int> indices;
	int mv = avti.size();
	while (mv > 0) {
		minTime = max(w, h);
		mv = 0;
		for (int i = 0; i < avti.size(); ++i) {
			if (!avti[i].moving) continue;
			mv = 1;
			for (int j = i + 1; j < avti.size(); ++j) {
				if (!avti[j].moving) continue;
				mv = 2;
				if (avti[i].dir != avti[j].dir) {
					int diffx = abs(avti[i].x - avti[j].x), diffy = abs(avti[i].y - avti[j].y);
					if (diffx == diffy) {
						if (minTime > diffx) {
							if (avti[i].dir == RIGHT && avti[i].x < avti[j].x && avti[i].y > avti[j].y) {
								minTime = diffx;
								indices.clear();
								indices.push_back(i);
								indices.push_back(j);
							} else if (avti[j].dir == RIGHT && avti[j].x < avti[i].x && avti[j].y > avti[i].y) {
								minTime = diffx;
								indices.clear();
								indices.push_back(i);
								indices.push_back(j);
							}
						} else if (minTime == diffx) {
							if (avti[i].dir == RIGHT && avti[i].x < avti[j].x && avti[i].y > avti[j].y) {
								indices.push_back(i);
								indices.push_back(j);
							} else if (avti[j].dir == RIGHT && avti[j].x < avti[i].x && avti[j].y > avti[i].y) {
								indices.push_back(i);
								indices.push_back(j);
							}
						}
					}
				}
			}
		}

		for (int i = 0; i < avti.size(); ++i) {
			if (avti[i].moving)
				avti[i].move(minTime);
		}
		for (int i = 0; i < indices.size(); ++i) {
			avti[indices[i]].dir ^= 1;
		}
		indices.clear();
		for (int i = 0; i < avti.size(); ++i) {
			if (avti[i].moving && avti[i].dir == UP && avti[i].y == h)
				avti[i].moving = false;
			else if (avti[i].moving && avti[i].dir == RIGHT && avti[i].x == w)
				avti[i].moving = false;
		}
	}

	for (int i = 0; i < avti.size(); ++i) {
		cout << avti[i].x << " " << avti[i].y << endl;
	}

	//system("pause");
	return 0;
}