Cod sursa(job #1394984)

Utilizator kagy85Kolumban Antal kagy85 Data 20 martie 2015 21:48:37
Problema Loto Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <fstream>
#include <map>
#include <cstring>

using namespace std;
//az n meximalis erteke
const int Modder=700099; //ezzel szamolunk modulokat
const unsigned short MaxN=100, LottoNr=6;

int v[Modder];
unsigned int a[MaxN], comb[MaxN*MaxN*MaxN][3], s, combnr;
unsigned short n;

int main(void)
{
    ifstream fi("loto.in", ios::in);
    ofstream fo("loto.out", ios::out);
    int i, j, k, c, idx2;
    long sum;
    bool won=false;

    memset(v, -1, Modder*sizeof(int));
    combnr=0;
    fi>>n>>s;
    for (i=0; i!=n; i++)
        fi>>a[i];
    for (i=0; (i!=n)&&(!won); i++)
        for (j=0; (j!=n)&&(!won); j++)
            for (k=0; (k!=n)&&(!won); k++)
                if ((sum=a[i]+a[j]+a[k])<=s)
                {
                    v[sum%Modder]=combnr;
                    comb[combnr][0]=a[i];
                    comb[combnr][1]=a[j];
                    comb[combnr][2]=a[k];
                    if ((idx2=v[(s-sum)%Modder])!=-1)
                    {
                        won=true; //megvan a megoldas
                        for (c=0; c!=3; c++)
                            fo<<comb[combnr][c]<<' '<<comb[idx2][c]<<' ';
                    }
                    combnr++;
                }

    if (!won)
        fo<<-1;
    fo.close();
    fi.close();

    return 0;
}