Cod sursa(job #856888)

Utilizator blechereyalBlecher Eyal blechereyal Data 17 ianuarie 2013 05:42:33
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <fstream>
#include <vector>
#define NMAX 102
#define SMAX 600000
#define MOD 666013
using namespace std;
using namespace __gnu_cxx;
ifstream f("loto.in");
ofstream g("loto.out");
typedef struct points {int a,b,c;} POINTS;
vector <int> sol;
vector <POINTS> hash[SMAX];
vector <POINTS>::iterator it;
int V[NMAX],N,S,sumah,suma;
int main()
{
    int i,j,k,suma;
    f>>N>>S;
    for (int i=1;i<=N;i++)
     f>>V[i];
    for (int i=1;i<=N;i++)
        for (int j=1;j<=N;j++)
            for (int k=1;k<=N;k++)
                {
                    suma=V[i]+V[j]+V[k];
                    if (suma<=S)
                        hash[suma%MOD].push_back({i,j,k});
                }

    for (int i=1;i<=N;i++)
        for (int j=1;j<=N;j++)
            for (int k=1;k<=N;k++)
                {
                    suma=V[i]+V[j]+V[k];
                    suma=S-suma;
                        for (it=hash[suma%MOD].begin();it!=hash[suma%MOD].end();it++)
                         {

                             if (V[(*it).a]+V[(*it).b]+V[(*it).c]==suma) {
                                            g<<V[i]<<" "<<V[j]<<" "<<V[k]<<" "<<V[(*it).a]<<" "<<V[(*it).b]<<" "<<V[(*it).c];
                                            return 0;
                                            }
                         }

                }


    return 0;
}