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。
接下来依次是这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;
}