Cod sursă (job #107348)

Utilizator avatar george-liviu Pereteanu George george-liviu IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 1,02 kb
Rundă Tema 12 clasele 9-10 2014/15 Status evaluat
Dată 18 ian. 2015 16:11:17 Scor 100
#include <cstdio>
using namespace std;

int c,t,m,x;


void citire()
{
    freopen("scv.in","r",stdin);
    freopen("scv.out","w",stdout);
    scanf("%d%d%d%d",&c,&t,&m,&x);
}

int z;
int nrscv;
int t_constructie;
int minerale;

int nrzile(int min, int scv)
//numarul de zile ca cantitatea min sa fie adunate de scv scv-uri
{
    int raspuns = min / (scv * m);
    if (raspuns % (scv * m) > 0)
        ++raspuns;
    return raspuns;
}

void simulare()
{
    nrscv = 1;
    minerale = 0;
    for (z = 0;minerale < x;minerale += nrscv * m,++z)
    {
        if (t_constructie > 0)
        {
            --t_constructie;
            if (t_constructie == 0)
                ++nrscv;
        }
        if (minerale >= c && t_constructie == 0 && nrzile(x - minerale, nrscv) > t + nrzile(c, 1))
        {//comanda de constructie a unui scv
            t_constructie = t;
            minerale -= c;
        }
    }
}

int main()
{
    citire();
    simulare();
    printf("%d\n",z);
    return 0;
}