Pagini recente » Cod sursa (job #1411742) | Cod sursa (job #729494) | Cod sursa (job #2641795) | Cod sursa (job #26070) | Cod sursa (job #984368)
Cod sursa(job #984368)
#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[MAXN],b[MAXN],c[MAXN],nrg=1,aux,semn;
int xx,yy;
nod_lista *l[MAXN],*p,*q,*r,*prev;
int main()
{
short int i,j;
f>>n>>m;
for(i=1;i<=n;i++)
f>>a[i]>>b[i]>>c[i];
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;}
p->nxt=NULL;
for(i=1;i<=n;i++){
aux=nrg;
for(j=1;j<=aux;j++){
p=l[j];
xx=p->x;
yy=p->y;
if(xx*a[i]+yy*b[i]+c[i]>0)
semn=1;
else
semn=-1;
prev=p;
p=p->nxt;
q=NULL;
for(p;p!=NULL;p=p->nxt){
xx=p->x;
yy=p->y;
if((xx*a[i]+yy*b[i]+c[i])*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;}
prev->nxt=p->nxt;
delete p;
p=prev;}
prev=p;}
if(q!=NULL){
q->nxt=NULL;
nrg++;}}}
g<<nrg<<'\n';
f.close();
g.close();
return 0;
}