CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:Chatne
Submission time:2015-09-29 15:30:05 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:44:34: error: 'ceil' was not declared in this scope
      retcount = ceil(bcount / 1.5);
                                  ^

Code

#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main() {
	cin.sync_with_stdio(false);

	int bcount;
	cin >> bcount;

	vector<int> alive(bcount), killed(bcount), uList(bcount), mList(bcount), kList(bcount);

	for (int i = 0; i < bcount; i++) {
		int a;
		cin >> a;
		uList[i] = a - 1;
		alive[i] = i;
	}
	for (int i = 0; i < bcount; i++) {
		int a;
		cin >> a;
		mList[i] = a - 1;
	}
	int i = 0;
	int fail = 0;
	while (1) {



		int rnd = rand() % (bcount-i);

		if (alive[rnd] == uList[i] || alive[rnd] == mList[i]) {
			
			if (fail < 4) {
				fail++;
				continue;
			}
			else {
				int retcount = (i < 2) ? i : 2;
				if (i == bcount - 1) {
					retcount = ceil(bcount / 1.5);
				}
				for (int j = 0; j < retcount; j++) {
					alive.push_back(killed[i - j - 1]);
				}
				i = i - retcount;
			}
			
		}

		kList[i] = alive[rnd] + 1;
		killed[i] = alive[rnd];
		alive.erase(alive.begin() + rnd);

		if (i < bcount-1) {
			i++;
		}
		else {
			for (int j = 0; j < bcount; j++){
				cout << kList[j] << " ";
			}
			break;
		}
	}
}