Pagini recente » Cod sursa (job #1551738) | Cod sursa (job #223048) | Cod sursa (job #1400546) | Cod sursa (job #673844) | Cod sursa (job #836764)
Cod sursa(job #836764)
// CPlusPlus Console Application.cpp : Defines the entry point for the console application.
//
#include <fstream>
#include <iostream>
#include <list>
#include <stdlib.h>
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 (int 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;
}