zoj 2870 || poj 3304 Segments

211 篇文章 0 订阅
134 篇文章 1 订阅

这个题也是,刚开始学计算几何,那个分类就有了,但是一直没看懂,刚才又看了一次,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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值