URAL 1963 Kite 计算几何

Kite

题目连接:

http://acm.hust.edu.cn/vjudge/contest/123332#problem/C

Description

Vova bought a kite construction kit in a market in Guangzhou. The next day the weather was good and he decided to make the kite and fly it. Manufacturing instructions, of course, were only in Chinese, so Vova decided that he can do without it. After a little tinkering, he constructed a kite in the form of a flat quadrangle and only needed to stick a tail to it.

And then Vova had to think about that: to what point of the quadrangle's border should he stick the kite tail? Intuition told him that in order to make the kite fly steadily, its tail should lie on some axis of symmetry of the quadrangle. On the left you can see two figures of stable kites, and on the right you can see two figures of unstable kites.

Problem illustration

How many points on the quadrangle border are there such that if we stick a tail to them, we get a stable kite?

Input

The four lines contain the coordinates of the quadrangle's vertices in a circular order. All coordinates are integers, their absolute values don't exceed 1 000. No three consecutive quadrangle vertices lie on the same line. The opposite sides of the quadrangle do not intersect.

Output

Print the number of points on the quadrangle border where you can attach the kite.

Sample Input

0 0

1 2

2 2

2 1

Sample Output

2

Hint

题意

给你个四边形,问你有多少个点在这个四边形的对称轴上

题解:

在对称轴上的点只有四边形的端点,以及端点之间的中点。

把这些点压进去,然后暴力去判断就好了。

代码

#include<bits/stdc++.h>
using namespace std;
const double INF = 1E200;
const double EP = 1E-6 ;
const int MAXV = 300 ;
const double PI = 3.14159265;
int vis[100];
/* 基本几何结构 */
struct POINT
{
double x;
double y;
POINT(double a=0, double b=0) { x=a; y=b;} //constructor
};
struct LINESEG
{
POINT s;
POINT e;
LINESEG(POINT a, POINT b) { s=a; e=b;}
LINESEG() { }
};
struct LINE // 直线的解析方程 a*x+b*y+c=0 为统一表示,约定 a >= 0
{
double a;
double b;
double c;
LINE(double d1=1, double d2=-1, double d3=0) {a=d1; b=d2; c=d3;}
};
double dist(POINT p1,POINT p2) // 返回两点之间欧氏距离
{
return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
double multiply(POINT sp,POINT ep,POINT op)
{
return((sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y));
}
double ptoldist(POINT p,LINESEG l)
{
return abs(multiply(p,l.e,l.s))/dist(l.s,l.e);
}
POINT p[100];
POINT tmp[10];
int main(){
for(int i=0;i<4;i++){
scanf("%lf%lf",&tmp[i].x,&tmp[i].y);
}
tmp[4]=tmp[0];
int cnt = 0;
for(int i=1;i<=4;i++){
p[cnt++]=tmp[i-1];
p[cnt].x=(tmp[i-1].x+tmp[i].x)/2.0;
p[cnt++].y=(tmp[i-1].y+tmp[i].y)/2.0;
}
int ans = 0;
int n = cnt;
int k = n/2;
for(int i=0;i+k<n;i++){
int flag = 0;
for(int j=0;j<=n;j++){
int a1 = (i+j+n)%n;
int a2 = (i-j+n)%n;
if(fabs(ptoldist(p[a1],LINESEG(p[i],p[i+k]))-ptoldist(p[a2],LINESEG(p[i],p[i+k])))>EP)
{
flag = 1;
break;
}
POINT c = POINT((p[a1].x+p[a2].x)/2.0,(p[a1].y+p[a2].y)/2.0);
if(ptoldist(c,LINESEG(p[i],p[i+k]))>EP){
flag = 1;
break;
}
double x1 = p[i].x - p[i+k].x;
double y1 = p[i].y - p[i+k].y;
double x2 = p[a1].x - p[a2].x;
double y2 = p[a1].y - p[a2].y; if(fabs(x1*x2+y1*y2)>EP){
flag = 1;
break;
}
}
if(flag==0)ans+=2;
}
cout<<ans<<endl;
}
上一篇:可视化(番外篇)——SWT总结


下一篇:html/html5中的download属性