标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13140 | Accepted: 3424 |
Description
Input
Output
Sample Input
1 4 9 11 2 1 5 7 1
Sample Output
F
题解:判断直线与矩形是否有公共点:a=y2-y1;b=x1-x2;c=x2*y1-x1*y2;
代码:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 using namespace std; 7 const int INF=0x3f3f3f3f; 8 const double PI=acos(-1.0); 9 typedef long long LL; 10 struct Node{ 11 int x,y; 12 }s,e,a,d; 13 int m,n,q; 14 int count(int x,int y){ 15 return m*x+n*y+q; 16 } 17 int main(){ 18 int T; 19 scanf("%d",&T); 20 while(T--){ 21 scanf("%d%d%d%d%d%d%d%d",&s.x,&s.y,&e.x,&e.y,&a.x,&a.y,&d.x,&d.y); 22 if(a.x>d.x){ 23 int temp=a.x; 24 a.x=d.x; 25 d.x=temp; 26 } 27 if(a.y<d.y){ 28 int temp=a.y; 29 a.y=d.y; 30 d.y=temp; 31 } 32 m=e.y-s.y; 33 n=s.x-e.x; 34 q=e.x*s.y-s.x*e.y; 35 if(count(a.x,a.y)*count(d.x,d.y)>0&&count(a.x,d.y)*count(d.x,a.y)>0){ 36 puts("F");continue; 37 } 38 if((s.x<a.x&&e.x<a.x)||(s.x>d.x&&e.x>d.x)||(s.y>a.y&&e.y>a.y)||(s.y<d.y&&e.y<d.y))//检查是否包含 39 puts("F"); 40 else puts("T"); 41 } 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4921536.html