这个题也是,刚开始学计算几何,那个分类就有了,但是一直没看懂,刚才又看了一次,YY了下,懂了。
求是否存在一条直线使得其他直线在它上面的投影有共同交点,如果存在,做这条直线的垂线,那么肯定和每个线段有交点的,那个交点肯定就是大家投影共同的交点。
然后直接找这条垂线即可,我想起来阿里巴巴那个1002了,基本是一样的,都可以用枚举任意两个端点来做。
这个题的话 有个坑姐的地方就是,如果两个点的距离小于1e-8,那么这两个点说明是相同的,就不能枚举以这两点为端点的线段了 = =。。
zoj这个题做的人太少了。。。一不小心第一了。。
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")
using namespace std;
const int MAX = 110;
struct point {
double x,y;
void get()
{
scanf("%lf%lf", &x, &y);
}
};
struct line{point a,b;};
line l[MAX];
point p[MAX*2];
const double eps = 1e-8;
bool dy(double x,double y) { return x > y + eps;} // x > y
bool xy(double x,double y) { return x < y - eps;} // x < y
bool dyd(double x,double y) { return x > y - eps;} // x >= y
bool xyd(double x,double y) { return x < y + eps;} // x <= y
bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y
double crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向 顺时针是正
{
return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);
}
double disp2p(point a,point b) // a b 两点之间的距离
{
return sqrt( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );
}
bool s2l_inst(point s1,point s2,point l1,point l2)//s是线段,l是直线
{ // xyd包括端点在直线上。xy是穿过
return xyd(crossProduct(l1,l2,s1) * crossProduct(l1,l2,s2),0.0);
}
bool inst(point a,point b,int n)
{
for(int i=0; i<n; i++)
if( !s2l_inst(l[i].a, l[i].b, a, b) )
return false;
return true;
}
bool solve(int cnt,int n)
{
for(int i=0; i<cnt; i++)
for(int k=i+1; k<cnt; k++)
{
if( disp2p(p[i], p[k]) < eps ) continue;
bool ans = inst(p[i], p[k], n);
if( ans ) return true;
}
return false;
}
int main()
{
int ncases, n;
scanf("%d", &ncases);
while( ncases-- )
{
scanf("%d", &n);
int cnt = 0;
for(int i=0; i<n; i++)
{
l[i].a.get();
l[i].b.get();
p[cnt++] = l[i].a;
p[cnt++] = l[i].b;
}
bool ans = solve(cnt, n);
if( ans )
puts("Yes!");
else
puts("No!");
}
return 0;
}