Pagini recente » Statistici Blowfish Ion (blowfishme) | Cod sursa (job #2544512) | Cod sursa (job #1057602) | Cod sursa (job #2975945) | Cod sursa (job #1711848)
#include<iostream>
#include<fstream>
#include<algorithm>
#define MAX 1000001
using namespace std;
typedef struct lista {
int info,nr;
lista *next;
}*nod;
int i,j,n,s,a[1050],rs=0;
nod h[MAX];
void add(int x,nod &y) {
nod p=new lista;
p->info=x;
p->nr=1;
p->next=y;
y=p;
}
void adaug(int x) {
for(nod p=h[x%MAX];p;p=p->next)
if(p->info==x) { ++p->nr; return; }
add(x,h[x%MAX]);
}
int search(int x) {
for(nod p=h[x%MAX];p;p=p->next)
if(p->info==x) return p->nr;
return 0;
}
int main()
{
ifstream f("oite.in");
ofstream g("oite.out");
f>>n>>s;
for(i=1;i<=n;++i)
f>>a[i];
for(i=1;i<n;++i)
{
for(j=i+1;j<=n;++j)
if(s-a[i]-a[j]>=0)
rs+=search(s-a[i]-a[j]);
for(j=1;j<i;++j)
adaug(a[i]+a[j]);
}
g<<rs<<endl;
return 0;
}