Cod sursa(job #1074170)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 7 ianuarie 2014 12:32:35
Problema Balanta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.41 kb
#include <iostream>
#include <fstream>
using namespace std;
int max(int a[], int b)
{
    int m = 0;
    for(int i=0; i< b; i++)
    {
            if(a[i] > m) m = a[i];
    }
    return m;
}
int check(int a)
{
    if(a< 0)
    {
          return 0-a;
    }
    if(a> 2)
    {
          return a-2;
    }
    return 0;
}
int main()
{
    ifstream fin("balanta.in");
    ofstream fout("balanta.out");
    int n, m, temp1, temp2, p = 0;
    fin>>n>>m;
    int arr[n], check_arr[n];
    for(int i=0; i< n; i++)
    {
            arr[i] = 1;
    }
    int temp[n];
    for(int i =0; i< m; i++)
    {
            fin>>temp1;
            for(int j=0; j< 2*temp1; j++)
            {
                    fin>>temp[j];
            }
            fin>>temp2;
            if(temp2 != 0)
            {
                     if(temp2 == 1)
                     {
                              for(int j=0; j< temp1; j++)
                              {
                                      arr[temp[j] - 1]++;
                              }
                              for(int j=temp1; j< 2*temp1; j++)
                              {
                                      arr[temp[j] - 1]--;
                              }
                     }
                     else if(temp2 == 2)
                     {
                          for(int j=temp1; j< 2*temp1; j++)
                          {
                                  arr[temp[j] - 1]++;
                          }
                          for(int j=0; j< temp1; j++)
                          {
                                  arr[temp[j] - 1]--;
                          }
                     }
            }
    }
    for(int i=0; i< n; i++)
    {
            check__arr[i] = check(arr[i]);
    }
    temp2 = max(check_arr, n);
    
    for(int i=0; i< n; i++)
    {
            if(arr[i] == max(arr, n)) p = i+1;
    }
    /*for(int i =0; i< n; i++)
    {
            cout<<arr[i]<<" ";
    }
    cout<<endl;*/
    /*for(int i=0; i< n; i++)
    {
            if(i == 0)
            {
                 if(arr[i] == 1 && arr[i+1] == 0) p = i+1;
            }
            else if(i == n-1)
            {
                 if(arr[i] == 1 && arr[i-1] == 0) p = i+1;
            }
                 else if(arr[i] == 1 && arr[i-1] == 0 && arr[i+1] == 0) p = i+1;
    }*/
    fout<<p<<endl;
    return 0;
}