Pagini recente » Cod sursa (job #45966) | Cod sursa (job #2149039) | Cod sursa (job #2856250) | Cod sursa (job #1560888) | Cod sursa (job #984376)
Cod sursa(job #984376)
#include <fstream>
#define MAXN 1005
using namespace std;
ifstream f("regiuni.in");
ofstream g("regiuni.out");
struct nod_lista{
short int x,y;
nod_lista *nxt;};
short int n,m,a,b,c,nrg=1,aux,semn;
int xx,yy;
nod_lista *l[MAXN],*p,*q,*r,*ant;
int main()
{
short int i,j;
f>>n>>m;
for(i=1;i<=n;i++)
f>>a>>b>>c;
l[1]=new nod_lista;
p=l[1];
f>>p->x>>p->y;
for(i=2;i<=m;i++){
q=new nod_lista;
f>>q->x>>q->y;
p->nxt=q;
p=q;}
ifstream f("regiuni.in");
f>>n>>m;
p->nxt=NULL;
for(i=1;i<=n;i++){
f>>a>>b>>c;
aux=nrg;
for(j=1;j<=aux;j++){
p=l[j];
xx=p->x;
yy=p->y;
if(xx*a+yy*b+c>0)
semn=1;
else
semn=-1;
ant=p;
p=p->nxt;
q=NULL;
for(p;p!=NULL;p=p->nxt){
xx=p->x;
yy=p->y;
if((xx*a+yy*b+c)*semn<0){
if(q==NULL){
l[nrg+1]=new nod_lista;
q=l[nrg+1];
q->x=xx;
q->y=yy;}
else{
r=new nod_lista;
r->x=xx;
r->y=yy;
q->nxt=r;
q=r;}
ant->nxt=p->nxt;
delete p;
p=ant;}
ant=p;}
if(q!=NULL){
q->nxt=NULL;
nrg++;}}}
g<<nrg<<'\n';
f.close();
g.close();
return 0;
}