Cod sursa(job #743809)

Utilizator GrimpowRadu Andrei Grimpow Data 6 mai 2012 00:14:04
Problema Regiuni Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include<stdio.h>
long int n,m,i,j,k,a,b,c,x[1001],y[1001],zone1,zone,z,left,right,st[1001],dr[1001],st1[1001],dr1[1001],aux;
int main()
{
	FILE *f,*g;
	f=fopen("regiuni.in","r");
	g=fopen("regiuni.out","w");
	fscanf(f,"%ld%ld",&n,&m);
	for(i=1;i<=n;i++)fscanf(f,"%ld%ld%ld",&a,&b,&c);
	for(i=1;i<=m;i++)fscanf(f,"%ld%ld",&x[i],&y[i]);
	fclose(f);
	f=fopen("regiuni.in","r");
	fscanf(f,"%ld%ld",&n,&m);
        zone=1;st[1]=1;dr[1]=m;
	for(i=1;i<=n;i++)
	 { fscanf(f,"%ld%ld%ld",&a,&b,&c);
	   zone1=0;
	   for(z=1;z<=zone;z++)
	   {left=st[z]-1;right=dr[z]+1;
	    while(left!=(right-1))
	    { if((a*x[left+1]+b*y[left+1]+c)>0) left++;
	      else {right--;
		  aux=x[left+1];x[left+1]=x[right];x[right]=aux;
		  aux=y[left+1];y[left+1]=y[right];y[right]=aux;}
	    }
	    if((left==(st[z]-1))||(right==(dr[z]+1)))
		{ zone1++;st1[zone1]=st[z];dr1[zone1]=dr[z];}
	    else
		{ zone1++;st1[zone1]=st[z];dr1[zone1]=left;
		  zone1++;st1[zone1]=right;dr1[zone1]=dr[z];}
	   }
	   zone=zone1;
	   for(z=1;z<=zone;z++)
	   { st[z]=st1[z];dr[z]=dr1[z];}
	 }
	fprintf(g,"%ld\n",zone);
	fcloseall();
	return 0;
}