Cod sursa(job #836755)

Utilizator bghimisFMI Ghimis Bogdan bghimis Data 16 decembrie 2012 18:24:03
Problema Zombie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.55 kb
// CPlusPlus Console Application.cpp : Defines the entry point for the console application.
//

#include <STDIO.H>
#include <WINDOWS.H>
#include <FSTREAM>
#include <IOSTREAM>
#include <LIST>

using namespace std;

int main(int argc, char* argv[])
{
	fstream cin ("zombie.in",  ios::in);
	fstream cout("zombie.out", ios::out);

	int chakraNeeded = 0;
	int streetLength, momentsOfTimeNr, chakraCost;
	list<int> *zombieTiming = new list<int>;

	cin >> streetLength >> momentsOfTimeNr >> chakraCost;
	for (int i = 0; i < momentsOfTimeNr; i++)
	{
		int temp; cin >> temp;
		zombieTiming->push_back(temp);
	}

	bool *street = (bool*)malloc(sizeof(bool) * streetLength);

	int latestZombie = zombieTiming->back();
	for (i = 1; i  <= latestZombie + streetLength; i++)
	{	
		if(zombieTiming->empty() == true)
			zombieTiming->push_back(0);

		if (zombieTiming->front() == i)
		{
			street[streetLength - 1] = true;
			zombieTiming->pop_front();
		}
		else
		{
			if (street[0] == true)
			{
				bool ok = false;
				for (int k = 1; k <= streetLength - 1; k++)
				{
					if(street[k] == true)
					{
						chakraNeeded += chakraCost;
						ok = true;
						street = (bool*)malloc(sizeof(bool) * streetLength);
						break;
					}
				}

				if(ok == false)
				{
					chakraNeeded += 1;
					street[0] = false;
				}
			}
		}		
		
		for (int k = 1; k <= streetLength - 1; k++)
		{
			if (street[k] == true)
			{
				street[k] = false;
				street[k - 1] = true;
			}
		}
	}

	cout << chakraNeeded << endl;

	return 0;
}