Cod sursa(job #75834)

Utilizator MarcvsHdrMihai Leonte MarcvsHdr Data 6 august 2007 12:01:12
Problema Count Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.64 kb
# include <stdio.h>

const long int MAXN=15500;
const long int NRBITI=15;
long int JUMATE;
long int a[MAXN+1][MAXN/NRBITI+2];
long int n,m;

long int min (long int a, long int b) {if (a>b) return b; return a;}
long int max (long int a, long int b) {if (a>b) return a; return b;}

void insert(long int aa, long int bb)
{
long int x,y,aux;
if (aa>JUMATE&&bb>JUMATE)
	{
	aa%=JUMATE;
	bb%=JUMATE;
	aux=aa;aa=bb;bb=aux;
	}
x=aa;
if (bb%NRBITI) y=bb/NRBITI+1;
else y=bb/NRBITI;
bb%=NRBITI;
if (!bb) bb=NRBITI;
a[x][y]|=((long int)1<<(bb-1));
}

void citire()
{
FILE *f=fopen("count.in","r");
fscanf(f,"%ld%ld",&n,&m);
JUMATE=n/2+1;
long int i,aa,bb;
for (i=1;i<=m;i++)
	{
	fscanf(f,"%ld%ld",&aa,&bb);
	insert(min(aa,bb),max(aa,bb));
	}
fclose(f);
}

int retrieve(long int i, long int j)
{
long int x,y,aux;
if (i>JUMATE&&j>JUMATE)
	{
	i%=JUMATE;
	j%=JUMATE;
	aux=i;i=j;j=aux;
	}
x=i;
if (j%NRBITI) y=j/NRBITI+1;
else y=j/NRBITI;
j%=NRBITI;
if (!j) j=NRBITI;
if (a[x][y]&((long int)1<<(j-1))) return 1;
return 0;
}

void scrie(long int max, long int count)
{
FILE *g=fopen("count.out","w");
fprintf(g,"%ld %ld\n",max,count);
fcloseall();
}

void gen()
{
long int i,j,k,l,max,count;
max=2;count=m;
for (i=1;i<=n;i++)
for (j=i+1;j<=n;j++)
	if (retrieve(i,j))
	for (k=j+1;k<=n;k++)
	if (retrieve(i,k)&&retrieve(j,k))
			{
			if (max<3) {max=3;count=0;}
			if (max==3) count++;
			for (l=k+1;l<=n;l++)
			if (retrieve(i,l)&&retrieve(j,l)&&retrieve(k,l))
				{
				if (max<4) {max=4;count=0;}
				if (max==4) count++;
				}
			}
scrie(max,count);
}

int main()
{
citire();
gen();
return 0;
}