AOJ661 跨越千山万水只为找到你

Description
在一个二维平面上,有n条直线和不重叠的两个点(点S,点T,数据保证S和T一定不在n条直线中的任何一条上)。问:从点S到点T最少需要跨越多少条直线?
注:题目有多组数据。

Input
第1行:测试数据组数t;
接下来依次是这t组数据,对于每一组数据:
第1行:n,0<n≤512;
第2行:Sx Sy Tx Ty,其中(Sx,Sy)是点S的坐标,(Tx,Ty)是点T的坐标;
第3~n+2行:x0 y0 x1 y1,点(x0,y0)和点(x1,y1)不重合,这两点表示一条直线;
第n+4行:空行。
上述数据中除n为整数外,都为实数,各数的绝对值大小不超过10 6

Output
一共t行,第i行对于第i组数据的答案。

Sample Input
Original Transformed
2
1
0 1 0 -1
-1 0 1 0

2
1 1 -1 -1
0 1 0 -1
-1 0 1 0


Sample Output
Original Transformed
1
2


第六届网络赛B题


/***********************************************************************************************************************
题意:略
思路:题目可转化为求多少条直线与线段ST相交 如果直线与ST相交 则必有点S、T在直线两侧 根据数学公式算一下异号就行
***********************************************************************************************************************/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <ctime>
using namespace std;
typedef struct{
	double x0 , y0 , x1 , y1;
}line;
line a[555];
int main()
{
	//freopen("data.in" , "r" , stdin);
	int t; scanf("%d" , &t);
	while(t--){
		int n; scanf("%d" , &n);
		line s;
		scanf("%lf%lf%lf%lf" , &s.x0 , &s.y0 , &s.x1 , &s.y1);
		int ans = 0;
		for(int i = 0 ; i < n ; i ++){
			scanf("%lf%lf%lf%lf" , &a[i].x0 , &a[i].y0 , &a[i].x1 , &a[i].y1);
			double ty1 = (a[i].y1 - a[i].y0) / (a[i].x1 - a[i].x0) * (s.x0 - a[i].x0) + a[i].y0;
            ty1 -= s.y0;
            double ty2 = (a[i].y1 - a[i].y0) / (a[i].x1 - a[i].x0) * (s.x1 - a[i].x0) + a[i].y0;
            ty2 -= s.y1;
            if(ty1 * ty2 < 0)
            	ans ++;
		}
		printf("%d\n" , ans);
	}
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值