Rezultati

Up. imeNalogaJezikRezultatČas oddaje
lisperator-2017 Jungle Speed C++ 100/100OK 11. maj '17 @ 18:26

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 3,152 MiB 0,004 s OK
#2 9/9 3,152 MiB 0,004 s OK
#3 9/9 3,152 MiB 0,004 s OK
#4 9/9 3,152 MiB 0,004 s OK
#5 9/9 3,063 MiB 0,004 s OK
#6 9/9 3,066 MiB 0,004 s OK
#7 9/9 3,059 MiB 0,004 s OK
#8 9/9 3,059 MiB 0,004 s OK
#9 9/9 3,152 MiB 0,004 s OK
#10 9/9 3,152 MiB 0,004 s OK
#11 10/10 3,090 MiB 0,004 s OK

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

using namespace std;

int N;

class Player {
	public:
		Player() {
			hand.reserve(72);
			discard.reserve(72);
		}

		void play() {
			if (hand.empty()) {
				for (int i = 0; i < discard.size(); ++i) {
					hand.push_back(discard[i]);
				}
				discard.clear();
			}
			discard.push_back(hand[0]);
			hand.erase(hand.begin());
		}

		void take(vector<short>& otherPile) {
			for (int i = 0; i < otherPile.size(); ++i) {
				hand.push_back(otherPile[i]);
			}
			otherPile.clear();
			for (int i = 0; i < discard.size(); ++i) {
				hand.push_back(discard[i]);
			}
			discard.clear();
		}

		vector<short> hand;
		vector<short> discard;
};

Player players[8];

short check(short activePlayer) {
	for (int i = 0; i < N; ++i) {
		if (i != activePlayer && players[i].discard.size()) {
			if (players[i].discard[players[i].discard.size() - 1] == players[activePlayer].discard[players[activePlayer].discard.size() - 1]) {
				return i;
			}
		}
	}
	return activePlayer;
}

int main() {
	cin >> N;
	short counter = 0;
	short num;
	while (cin >> num) {
		players[counter % N].hand.insert(players[counter % N].hand.begin(), num);
		++counter;
	}

	short activePlayer = 0;
	short winner = -1;

	while (true) {
		players[activePlayer].play();
		short c = check(activePlayer);
		if (c != activePlayer) {
			players[activePlayer].take(players[c].discard);
			if (players[c].hand.size() + players[c].discard.size() == 0) {
				winner = c + 1;
				break;
			}
			--activePlayer;
		}
		activePlayer = (activePlayer + 1) % N;
	}

	cout << winner << endl;

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