## 866- WHY get WA?

Moderator: Board moderators

### 866- WHY get WA?

who can give me some test case?
thanks.
Last edited by huicpc0215 on Thu Oct 13, 2011 7:48 pm, edited 1 time in total.
huicpc0215
New poster

Posts: 2
Joined: Wed Oct 12, 2011 3:04 pm

### Re: 866- WHY get WA?

this is my code.
this is my solution:
every segment, intersect with every other segment,count how many parts can be divided. at lase, get the sum.
who can help me?

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;

#define sgn(a) (a)>eps?1:((a)<-eps?-1:0)
#define MAXN 110
#define eps 1e-5
#define INF 1e9
struct pt {
double x,y;
pt(){x=0;y=0;}
pt(double a,double b){x=a;y=b;}
pt operator -(const pt &a)const {return pt(x-a.x,y-a.y);}
pt operator +(const pt &a)const {return pt(x+a.x,y+a.y);}
double operator *(const pt &a)const {return x*a.x+y*a.y;}
double operator ^(const pt &a)const {return x*a.y-y*a.x;}
pt operator *(const double &a)const {return pt(x*a,y*a);}
}pnt[10000];
bool eql(pt a,pt b)
{
if(fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps)return true;
return false;
}
struct line{
pt a,b;
}li[10000];
int dblcmp(double d)
{
if(fabs(d)<eps)return 0;
return (d>0)?1:-1;
}
int SegCross(pt p1,pt p2,pt p3,pt p4,pt &p) //if intersect,get intersectPoint
{
double s1,s2,s3,s4;
int d1,d2,d3,d4;
d1=dblcmp(s1=p2-p1^p3-p1); //s1=fabs(area(p1,p2,p3)*2);
d2=dblcmp(s2=p2-p1^p4-p1); //s2=fabs(area(p1,p2,p4)*2);
d3=dblcmp(s3=p4-p3^p1-p3); //s3=fabs(area(p3,p4,p1)*2);
d4=dblcmp(s4=p4-p3^p2-p3); //s4=fabs(area(p3,p4,p2)*2);
//printf("%d %d %d %d\n",d1,d2,d3,d4);
if((d1^d2)==-2&&(d3^d4)==-2) //if intersect , getPoint P
{
p.x=(p4.x*s1-p3.x*s2)/(s1-s2);
p.y=(p4.y*s1-p3.y*s2)/(s1-s2);
return 1;
}
if(d3==0&&(dblcmp((p3-p1)*(p4-p1))<=0)|| // p1 is on the line of p3 and p4
d4==0&&(dblcmp((p3-p2)*(p4-p2))<=0))return 0; // p2 is on the line of p3 and p4
if(d1==0&&(dblcmp((p1-p3)*(p2-p3))<=0)){p=p3;return 1;} // p3 is on the line of p1 and p2
if(d2==0&&(dblcmp((p1-p4)*(p2-p4))<=0)){p=p4;return 1;} // p4 is on the line of p1 and p2
return 0;
}
int main()
{
int t,cnt,n;
int k;
int ptcnt;
int ans;
pt tmp;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ans=0;
for(int i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&li[i].a.x,&li[i].a.y,&li[i].b.x,&li[i].b.y);
for(int i=0;i<n;i++)
{
ptcnt=0;cnt=1;
for(int j=0;j<n;j++)
{
if(j==i)continue;
if(SegCross(li[i].a,li[i].b,li[j].a,li[j].b,tmp))
{
for(k=0;k<ptcnt;k++)
if(eql(pnt[k],tmp))
break;
if(k==ptcnt)
{
pnt[ptcnt++]=tmp;
cnt++;
}
}
}
ans+=cnt;
}
printf("%d\n",ans);
if(t>1)printf("\n");
}
return 0;
}
huicpc0215
New poster

Posts: 2
Joined: Wed Oct 12, 2011 3:04 pm