B,csu'all^_^!t

湖南省第十二届大学生计算机程序设计竞赛$J$题
计算几何。
#pragma comment(linker, "/STACK:,")
#include&cstdio&
#include&cstring&
#include&cmath&
#include&algorithm&
#include&vector&
#include&map&
#include&set&
#include&queue&
#include&stack&
#include&iostream&
using namespace
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
template &class T&
inline void read(T &x)
char c = getchar();
while(!isdigit(c)) c = getchar();
while(isdigit(c))
x = x * 10 + c - '0';
c = getchar();
const int maxn=555;
const int maxisn=10;
int dcmp(double x)
if(x&eps) return 1;
return x&-eps ? -1 : 0;
inline double Sqr(double x)
return x*x;
struct Point
double x,y;
Point(double x,double y):x(x),y(y) {};
friend Point operator + (const Point &a,const Point &b)
return Point(a.x+b.x,a.y+b.y);
friend Point operator - (const Point &a,const Point &b)
return Point(a.x-b.x,a.y-b.y);
friend bool operator == (const Point &a,const Point &b)
return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
friend Point operator * (const Point &a,const double &b)
return Point(a.x*b,a.y*b);
friend Point operator * (const double &a,const Point &b)
return Point(a*b.x,a*b.y);
friend Point operator / (const Point &a,const double &b)
return Point(a.x/b,a.y/b);
friend bool operator & (const Point &a, const Point &b)
return a.x & b.x || (a.x == b.x && a.y & b.y);
inline double dot(const Point &b)const
return x*b.x+y*b.y;
inline double cross(const Point &b,const Point &c)const
return (b.x-x)*(c.y-y)-(c.x-x)*(b.y-y);
Point LineCross(const Point &a,const Point &b,const Point &c,const Point &d)
double u=a.cross(b,c),v=b.cross(a,d);
return Point((c.x*v+d.x*u)/(u+v),(c.y*v+d.y*u)/(u+v));
double PolygonArea(Point p[],int n)
if(n&3) return 0.0;
double s=p[0].y*(p[n-1].x-p[1].x);
p[n]=p[0];
for(int i=1; i&n; i++)
s+=p[i].y*(p[i-1].x-p[i+1].x);
return fabs(s*0.5);
double CPIA(Point a[],Point b[],int na,int nb)
Point p[maxisn],temp[maxisn];
int i,j,tn,sflag,
a[na]=a[0],b[nb]=b[0];
memcpy(p,b,sizeof(Point)*(nb+1));
for(i=0; i&na&&nb&2; ++i)
sflag=dcmp(a[i].cross(a[i+1],p[0]));
for(j=tn=0; j& ++j,sflag=eflag)
if(sflag&=0) temp[tn++]=p[j];
eflag=dcmp(a[i].cross(a[i+1],p[j+1]));
if((sflag^eflag)==-2)
temp[tn++]=LineCross(a[i],a[i+1],p[j],p[j+1]);
memcpy(p,temp,sizeof(Point)*tn);
nb=tn,p[nb]=p[0];
if(nb&3) return 0.0;
return PolygonArea(p,nb);
double SPIA(Point a[],Point b[],int na,int nb)
Point t1[4],t2[4];
double res=0.0,if_clock_t1,if_clock_t2;
a[na]=t1[0]=a[0];
b[nb]=t2[0]=b[0];
for(i=2; i& i++)
t1[1]=a[i-1],t1[2]=a[i];
if_clock_t1=dcmp(t1[0].cross(t1[1],t1[2]));
if(if_clock_t1&0) swap(t1[1],t1[2]);
for(j=2; j& j++)
t2[1]=b[j-1],t2[2]=b[j];
if_clock_t2=dcmp(t2[0].cross(t2[1],t2[2]));
if(if_clock_t2&0) swap(t2[1],t2[2]);
res+=CPIA(t1,t2,3,3)*if_clock_t1*if_clock_t2;
Point a[222],b[222];
Point aa[222],bb[222];
int main()
int n1,n2;
double x1,y1,x2,y2,x3,y3,x4,y4;
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4))
n1=3,n2=4;
a[0].x=x1; a[0].y=y1;
a[1].x=x1; a[1].y=y2;
a[2].x=x2; a[2].y=y1;
b[0].x=x3; b[0].y=y3;
b[1].x=x3; b[1].y=y4;
b[2].x=x4; b[2].y=y4;
b[3].x=x4; b[3].y=y3;
printf("%.6lf\n",abs(SPIA(a,b,n1,n2)));
阅读(...) 评论():中南大学网球社新一届招干开始了!!!!详细情况进入 了解哦~~求顶贴!!
:【温布尔登快讯】李娜6-2/6-0胜文奇,晋级温网八强。
:李娜拒绝冷门4-6/6-0/8-6逆转对手进温网16强,这场比赛让主页君看到11年温网的翻版。
:世界排名第135位的比利时老将达尔西斯 7-6(4)7-6(8) 6-4爆大冷淘汰纳达尔,至此温网开赛第一天男单女单5号种子都已经出局。
:四级刚刚考完,祝大家逢考必过,下午六级党加油过过过!!
他们也是中南大学网球社的关注者:
中南大学网球社
人人移动客户端下载系统发生错误
系统发生错误
您可以选择 [
[ 错误信息 ]
您浏览的页面暂时发生了错误!请稍后再试~
ThinkPHP 2.0 { Fast & Simple OOP PHP Framework } -- [ WE CAN DO IT JUST THINK IT ]

我要回帖

更多关于 csu500b 的文章

 

随机推荐