Cod sursa(job #2276024)

Utilizator stefanut999Paul Colta stefanut999 Data 3 noiembrie 2018 22:13:08
Problema Cautare binara Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.22 kb
#include <fstream>
#define NMAX 10000
using namespace std;
ifstream fin("pic.in");
ofstream fout("pic.out");
int v,n,a[NMAX][NMAX],b[NMAX][NMAX],m,tempo,pierd;
bool sd[NMAX][NMAX];

void citire()
{
    fin>>v>>n;
    int i,j;
    for(i = 1; i <= n; i++)
        for(j = 1; j <= i; j++)
            fin>>a[i][j];
    /*for(i = 1; i <= n; i++)
       {for(j = 1; j <= i; j++)
           fout<<a[i][j]<<' ';
       fout<<'\n';}
    */
}

void rezolva_1()
{
    int i,j,t,s,maximao = -1,p;
    for(i = 1; i <= n; i++)
    {
        s = 0;
        for(j = 1; j <= i; j++)
            s += a[i][j];
        if(maximao < s)
        {
            maximao = s;
            p = i;
        }
    }
    fout<<p;
}

void parcurgere()
{
    int x, y ;
    bool okeanu = 1;
    x = y = 1;
    while(okeanu && x <= n)
        while(okeanu && y <= x)
        {
            if(x == 1)
                tempo++;
            if(b[x][y] + 1 <= a[x][y])
            {
                b[x][y]++;
                x = y = 1;
            }
            else
            {
                if(x < n)
                {
                    if(sd[x][y] == 0)
                    {
                        sd[x][y] = 1;
                        x++;
                    }
                    else
                    {
                        sd[x][y] = 0;
                        x++;
                        y++;
                    }
                }
                else
                {
                    int t;
                    bool ok = 1;
                    pierd++;
                    for(t = 1; t <= n; t++)
                        if(b[n][t] != a[n][t])
                        {
                            x = y = 1;
                            ok = 0;
                            break;
                        }
                    if(ok)
                        okeanu = 0;
                }
            }
        }
}

void rezolva_2()
{
    parcurgere();
//long long int rez = (tempo+1)/n;
    fout<<tempo - 1<<' '<<pierd - 1;
}

int main()
{
    citire();
    if(v == 1)
        rezolva_1();
    else
        rezolva_2();
    fin.close();
    fout.close();
    return 0;
}