Cod sursa(job #1217876)

Utilizator vasica38Vasile Catana vasica38 Data 8 august 2014 15:18:51
Problema Loto Scor 65
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb

#include<fstream>
using namespace std;
const int modulo=666013;
ifstream cin("loto.in");
ofstream cout("loto.out");

long long  i,j,k,s,n,loto[150];
typedef struct lista
            {
                long long info,poz1,poz2,poz3;
                lista *next;

            }*nod;

nod a[666013],r;
bool cauta(int x)
{
    int m=x%modulo;
    r=a[m];
    while (r)
    {
        if (r->info==x) return 0;
        r=r->next;
    }
    return 1;
}

void add(int x)
{
    int m= x % modulo;
    if (cauta(x)==1)
    {
        nod r=new lista;
        r->info=x;
        r->poz1=i;
        r->poz2=j;
        r->poz3
        =k;
        r->next=a[m];
        a[m]=r;
    }


}
void read()
{
    cin>>n>>s;
    for (i=1; i<=n ; ++i) cin>>loto[i];
    //for (i=1; i<=n ; ++i) cout<<loto[i]<<" ";

}


int main()
{
    read();
    int sol=1;
    for (i=1; i<=n; ++i)
        for (j=1; j<=n ; ++j)
            for (k=1; k<=n; ++k) add(loto[i]+loto[j]+loto[k]);
    for (i=1; i<=n; ++i)
        if (sol)
        for (j=1; j<=n; ++j)
            if (sol)
            for (k=1; k<=n; ++k)
                if (cauta(s-(loto[i]+loto[j]+loto[k]))==0)
                        {
                            cout<<loto[r->poz1]<<" "<<loto[r->poz2]<<" "<<loto[r->poz3]<<" "<<loto[i]<<" "<<loto[j]<<" "<<loto[k]<<" "<<"\n";
                            sol=0;
                            break;
                        }
   if (sol==1) cout<<-1;
   // cout<<cauta(6);
    cin.close();
    cout.close();
    return 0;
}