Cod sursa(job #76927)

Utilizator alex23alexandru andronache alex23 Data 12 august 2007 12:13:51
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <stdio.h>
#include <math.h>

struct pct{
int x,y;
};

pct v[1100];
int st[1100],k,max,p,n,i;

int Am_Succesor()
 {if (st[k]<n) {st[k]++;
		max=st[k];
		return 1;
		}
  return 0;
  }

int E_Valid()

 {return 1;
  }

int solutie()
 {if (k==4) return 1;
  return 0;
  }

int tipar()
 {
  if ((v[st[1]].y-v[st[2]].y)*(v[st[3]].x-v[st[4]].x)==
	  (v[st[3]].y-v[st[4]].y)*(v[st[1]].x-v[st[2]].x)) p++;
  if ((v[st[1]].y-v[st[3]].y)*(v[st[2]].x-v[st[4]].x)==
	  (v[st[2]].y-v[st[4]].y)*(v[st[1]].x-v[st[3]].x)) p++;
  if ((v[st[1]].y-v[st[4]].y)*(v[st[3]].x-v[st[2]].x)==
	  (v[st[3]].y-v[st[2]].y)*(v[st[1]].x-v[st[4]].x)) p++;
  }

void back()
{int as,i;k=1;
 st[k]=max;
 while (k>0)
  {
    do {} while ((as=Am_Succesor()) && !E_Valid());
    if (as)
      if (solutie()) tipar();
	  else {k++;st[k]=max;}
      else {k--;
	    max=st[k];
	    }
    }
  }


int main()
{FILE *fin,*fout;

fin=fopen("trapez.in","r");
fscanf(fin,"%d",&n);
for (i=1;i<=n;i++)
  fscanf(fin,"%d %d",&v[i].x,&v[i].y);
fclose(fin);

max=0;p=0;
back();

fout=fopen("trapez.out","w");
fprintf(fout,"%d",p);
fclose(fout);

return 0;
}