1086 You can Solve a Geometry Problem too
来源:互联网 发布:非农数据分析软件 编辑:程序博客网 时间:2024/06/07 20:13
#include<iostream>
#include<math.h>
using namespace std;
struct point
{
double x;
double y;
};
struct point p[100];
struct point q[100];
double cross(point w1,point w2,point w3)
{
return (w2.x-w1.x)*(w3.y-w1.y)-(w2.y-w1.y)*(w3.x-w1.x);
}
int on(point w1,point w2,point w3)
{
return (w1.x-w2.x)*(w1.x-w3.x)+(w1.y-w2.y)*(w1.y-w3.y);
}
int three(double d)
{
if(fabs(d)<1e-6)return 0;
else if(d>0)return 1;
else return -1;
}
int findcross(point x1,point x2,point y1,point y2)
{
int a,b,c,d;
a=three(cross(x1,x2,y1));
b=three(cross(x1,x2,y2));
c=three(cross(y1,y2,x1));
d=three(cross(y1,y2,x2));
if(a*b<0&&c*d<0)return 1;
if(a==0&&on(x2,x1,y1)<=0) return 2;
if(b==0&&on(y2,x1,y1)<=0) return 2;
if(c==0&&on(x1,y1,y2)<=0) return 2;
if(d==0&&on(x2,y1,y2)<=0) return 2;
return 0;
}
void main()
{
int sum,i,j,n;
while(cin>>n&&n!=0)
{
for(i=1,sum=0;i<=n;i++)cin>>p[i].x>>p[i].y>>q[i].x>>q[i].y;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(findcross(p[i],q[i],p[j],q[j]))sum++;
cout<<sum<<endl;
}
}
#include<math.h>
using namespace std;
struct point
{
double x;
double y;
};
struct point p[100];
struct point q[100];
double cross(point w1,point w2,point w3)
{
return (w2.x-w1.x)*(w3.y-w1.y)-(w2.y-w1.y)*(w3.x-w1.x);
}
int on(point w1,point w2,point w3)
{
return (w1.x-w2.x)*(w1.x-w3.x)+(w1.y-w2.y)*(w1.y-w3.y);
}
int three(double d)
{
if(fabs(d)<1e-6)return 0;
else if(d>0)return 1;
else return -1;
}
int findcross(point x1,point x2,point y1,point y2)
{
int a,b,c,d;
a=three(cross(x1,x2,y1));
b=three(cross(x1,x2,y2));
c=three(cross(y1,y2,x1));
d=three(cross(y1,y2,x2));
if(a*b<0&&c*d<0)return 1;
if(a==0&&on(x2,x1,y1)<=0) return 2;
if(b==0&&on(y2,x1,y1)<=0) return 2;
if(c==0&&on(x1,y1,y2)<=0) return 2;
if(d==0&&on(x2,y1,y2)<=0) return 2;
return 0;
}
void main()
{
int sum,i,j,n;
while(cin>>n&&n!=0)
{
for(i=1,sum=0;i<=n;i++)cin>>p[i].x>>p[i].y>>q[i].x>>q[i].y;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(findcross(p[i],q[i],p[j],q[j]))sum++;
cout<<sum<<endl;
}
}
- You can Solve a Geometry Problem too
- You can Solve a Geometry Problem too
- You can Solve a Geometry Problem too
- You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- HDOJ 1086 You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu/hdoj 1086 You can Solve a Geometry Problem too
- hdu-1086You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU 1086:You can Solve a Geometry Problem too
- HDU 1086You can Solve a Geometry Problem too
- 严重: IOException while loading persisted sessions: java.io.EOFException
- 1061 Rightmost Digit
- 1071 The area
- 1085 Holding Bin-Laden Captive!
- 2008 October 20th Monday (十月 二十日 月曜日)
- 1086 You can Solve a Geometry Problem too
- 1108 最小公倍数
- 2008 October 21th Tuesday (十月 二十一日 火曜日)
- 1115 Lifting the Stone
- Objective-C
- 2008 October 23th Thursday (十月 二十三日 木曜日)
- 1170 Balloon Comes!
- 2008 October 24th Friday (十月 二十四日 金曜日)
- 2008 October 27th Monday (十月 二十七日 月曜日)