i got WA. the test cases in this post is ok to my code
here is my code
plz plz someone help me
[cod#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int fun(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4)
{
double a1 = y1-y2;
int t=0;
double b1 = -(x1-x2);
double c1 = (y1*(x1-x2))-(x1*(y1-y2));
double d1 = (a1*x3) + (b1*y3) + c1;
double d2 = (a1*x4) + (b1*y4) + c1;
if((x1==x3&&y1==y3) || (x1==x4&&y1==y4) || (x2==x3&&y2==y3) || (x2==x4&&y2==y4))
{
t=1;
}
else if((d1>=0 && d2<0) || (d2>=0&& d1<0) ||(d1==0&&d2>0) || (d2==0 && d1>0))
{
double a2 = y3-y4;
double b2 = -(x3-x4);
double c2 = (y3*(x3-x4))-(x3*(y3-y4));
double d3 = (a2*x1) + (b2*y1) + c2;
double d4 = (a2*x2) + (b2*y2) + c2;
if((d3>=0 && d4<0) || (d4>=0&& d3<0))
t= 1;
else if(((d1>=0 && d2<0) || (d2>=0&& d1<0)) && ((d3==0&&d4>0) && (d4==0&&d3>0)))
t=1;
}
return t;
}
int fun02(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4 ,int i,int j)
{
int t1=0;
if(x1 != 1000 && x3 != 1000)
{
double s,t;
if( x1-x2==0)
s=90;
else
s = (y1 - y2)/(x1-x2);
if( x3-x4==0)
t=90;
else
t = (y3 - y4)/(x3-x4);
if(s==t && j != i)
{
double a1 = y1-y2;
double b1 = -(x1-x2);
double a2 = y3-y4;
double b2 = -(x3-x4);
double c1 = (y1*(x1-x2))-(x1*(y1-y2));
double c2 = (y3*(x3-x4))-(x3*(y3-y4));
if(c1==c2|| (c1/sqrt(a1*a1 + b1*b1))==(c2/sqrt(a2*a2+b2*b2)))
{
if(x1<x2)
{
if(x1<= x3 && x3<=x2)
t1=1;
else if(x1<=x4 && x4<=x2)
t1=1;
}
else
{
if(x1<= x3 && x3<=x2)
t1=1;
else if(x1<=x4 && x4<=x2)
t1=1;
}
if(x3<x4)
{
if(x1<= x3 && x3<=x2)
t1=1;
else if(x1<=x4 && x4<=x2)
t1=1;
}
else
{
if(x1<= x3 && x3<=x2)
t1=1;
else if(x1<=x4 && x4<=x2)
t1=1;
}
}
}
}
return t1;
}
int main()
{
int n1;
while(scanf("%d",&n1)==1)
{
double arr[11][5] ,brr[11][5];
int c=0;
for(int i=0 ; i< n1 ;i++)
{
scanf("%lf%lf%lf%lf",&brr[0] ,&brr[1],&brr[2],&brr[3]);
}
for(int i=0 ; i<n1 ; i++)
{
for(int j= 0; j< n1 ; j++)
{
double x1=brr[0],x2=brr[2],x3=brr[j][0],x4=brr[j][2];
double y1=brr[1],y2=brr[3],y3=brr[j][1],y4=brr[j][3];
int t1 = fun02(x1,x2,x3,x4,y1,y2,y3,y4 ,i,j);
if(t1==1)
{
double d[7],max=0,max1=0,X1=0,Y1=0,X2=0,Y2=0;
d[1] = abs(x1-x2);
if(d[1]>=max && max1<=(abs(y1-y2)))
{
max=d[1];
max1 =abs(y1-y2);
X1=x1,Y1=y1,X2=x2,Y2=y2;
}
d[2]=abs(x1-x3);
if(d[2]>=max && max1<=(abs(y1-y3)))
{
max=d[2];
max1 =abs(y1-y3);
X1=x1,Y1=y1,X2=x3,Y2=y3;
}
d[3]=abs(x1-x4);
if(d[3]>=max && max1<=(abs(y1-y4)))
{
max=d[3];
max1 =abs(y1-y4);
X1=x1,Y1=y1,X2=x4,Y2=y4;
}
d[4]=abs(x2-x3);
if(d[4]>=max && max1<=(abs(y2-y3)))
{
max=d[4];
max1 =abs(y2-y3);
X1=x2,Y1=y2,X2=x3,Y2=y3;
}
d[5]=abs(x2-x4);
if(d[5]>=max && max1<=(abs(y2-y4)))
{
max=d[5];
max1 =abs(y2-y4);
X1=x2,Y1=y2,X2=x4,Y2=y4;
}
d[6]=abs(x3-x4);
if(d[6]>=max && max1<=(abs(y3-y4)))
{
max=d[6];
max1 =abs(y3-y4);
X1=x3,Y1=y3,X2=x4,Y2=y4;
}
brr[0]=X1,brr[1]=Y1,brr[i][2]=X2,brr[i][3]=Y2;
brr[j][0]=brr[j][1]=brr[j][2]=brr[j][3]=1000;
}
}
}
int n=0;
for(int i=0; i<n1;i++)
{
if(brr[i][0]<1000)
{
arr[n][0]=brr[i][0];
arr[n][1]=brr[i][1];
arr[n][2]=brr[i][2];
arr[n][3]=brr[i][3];
n++;
}
}
for(int i =0 ;i< n; i++)
{
for(int j=i+1 ; j<n;j++)
{
double x1=arr[i][0],x2=arr[i][2],x3=arr[j][0],x4=arr[j][2];
double y1=arr[i][1],y2=arr[i][3],y3=arr[j][1],y4=arr[j][3];
int r = fun(x1,x2,x3,x4,y1,y2,y3,y4);
if(r==1)
{
for(int k=j+1;k<n;k++)
{
x1=arr[i][0],x2=arr[i][2],x3=arr[k][0],x4=arr[k][2];
y1=arr[i][1],y2=arr[i][3],y3=arr[k][1],y4=arr[k][3];
double a1 = y1-y2;
double b1 = -(x1-x2);
double c1 = (y1*(x1-x2))-(x1*(y1-y2));
double a2 = y3-y4;
double b2 = -(x3-x4);
double c2 = (y3*(x3-x4))-(x3*(y3-y4));
int r1=fun(x1,x2,x3,x4,y1,y2,y3,y4);
x1=arr[j][0],x2=arr[j][2],x3=arr[k][0],x4=arr[k][2];
y1=arr[j][1],y2=arr[j][3],y3=arr[k][1],y4=arr[k][3];
double a3 = y1-y2;
double b3 = -(x1-x2);
double c3 = (y1*(x1-x2))-(x1*(y1-y2));
int r2=fun(x1,x2,x3,x4,y1,y2,y3,y4);
double q = (a1*(b2*c3-b3*c2)) + (b1*(a3*c2-a2*c3)) + (c1*(a2*b3-a3*b2));
if(r1==1 && r2==1 && q !=0)
{
c++;
}
}
}
}
}
printf("%d\n",c);
}
return 0;
}
e][/code]
10979 - How Many Triangles?
All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
Return to “Volume 109 (10900-10999)”
Jump to
- Real Time Contests and Last Minute Information
- ↳ General
- ↳ Real Time Clarification
- ↳ Fixing Mistakes
- ↳ HOWTOs
- ↳ Bugs and suggestions
- New system
- ↳ FAQ
- ↳ Bugs and suggestions
- Let's make some programs!
- ↳ Other words
- ↳ Algorithms
- ↳ New features
- Help on the Problemset
- ↳ Volume 1 (100-199)
- ↳ Volume 2 (200-299)
- ↳ Volume 3 (300-399)
- ↳ Volume 4 (400-499)
- ↳ Volume 5 (500-599)
- ↳ Volume 6 (600-699)
- ↳ Volume 7 (700-799)
- ↳ Volume 8 (800-899)
- ↳ Volume 9 (900-999)
- ↳ Volume 10 (1000-1099)
- ↳ Volume 11 (1100-1199)
- ↳ Volume 12 (1200-1299)
- ↳ Volume 13 (1300-1399)
- ↳ Volume 14 (1400-1499)
- ↳ Volume 15 (1500-1599)
- ↳ Volume 16 (1600-1699)
- ↳ Volume 17 (1700-1799)
- ↳ Volume 100 (10000-10099)
- ↳ Volume 101 (10100-10199)
- ↳ Volume 102 (10200-10299)
- ↳ Volume 103 (10300-10399)
- ↳ Volume 104 (10400-10499)
- ↳ Volume 105 (10500-10599)
- ↳ Volume 106 (10600-10699)
- ↳ Volume 107 (10700-10799)
- ↳ Volume 108 (10800-10899)
- ↳ Volume 109 (10900-10999)
- ↳ Volume 110 (11000-11099)
- ↳ Volume 111 (11100-11199)
- ↳ Volume 112 (11200-11299)
- ↳ Volume 113 (11300-11399)
- ↳ Volume 114 (11400-11499)
- ↳ Volume 115 (11500-11599)
- ↳ Volume 116 (11600-11699)
- ↳ Volume 117 (11700-11799)
- ↳ Volume 118 (11800-11899)
- ↳ Volume 119 (11900-11999)
- ↳ Volume 120 (12000-12099)
- ↳ Volume 121 (12100-12199)
- ↳ Volume 122 (12200-12299)
- ↳ Volume 123 (12300-12399)
- ↳ Volume 124 (12400-12499)
- ↳ Volume 125 (12500-12599)
- ↳ Volume 126 (12600-12699)
- ↳ Volume 127 (12700-12799)
- ↳ Volume 128 (12800-12899)
- ↳ Volume 129 (12900-12999)
- ↳ Volume 130 (13000-13099)
- ↳ Volume 131 (13100-13199)
- Help on languages
- ↳ C
- ↳ C++
- ↳ Pascal
- ↳ Java
- Off Topic
- ↳ Off topic (General chit-chat)
- Category
- ↳ ACM ICPC Archive Board