Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮忙看一下我的1410错在那里啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#include"stdio.h" int min(int a,int b){return a<=b?a:b;} int max(int a,int b){return a>b?a:b;} int tt(int a[]) { int xx1,xx2,dx1,dx2,xy1,xy2,dy1,dy2;double k0,k1,x0,y0; xx1=min(a[0],a[2]);dx1=max(a[0],a[2]); xy1=min(a[1],a[3]);dy1=max(a[1],a[3]); xx2=min(a[4],a[6]);dx2=max(a[4],a[6]); xy2=min(a[5],a[7]);dy2=max(a[5],a[7]); if(a[0]!=a[2]) \\如果线段的斜率存在 if(xx1>xx2&&dx1<dx2&&xy1>xy2&&dy1<dy2) return 1;\\线段在矩形框内 else \\线段不在矩形框内 {k0=1.0*(a[3]-a[1])/(a[2]-a[0]);k1=1.0/k0; \\ k0为线段的斜率 \\计算该线段是否与矩形框各边相交 y0=k0*(a[4]-a[0])+a[1]; if((y0>=xy2)&&(y0<=dy2)&&(y0>=xy1)&&(y0<=dy1)) return 1; y0=k0*(a[6]-a[0])+a[1]; if((y0>=xy2)&&(y0<=dy2)&&(y0>=xy1)&&(y0<=dy1)) return 1; x0=k1*(a[5]-a[1])+a[0]; if((x0>=xx2)&&(x0<=dx2)&&(x0>=xx1)&&(x0<=dx1)) return 1; x0=k1*(a[7]-a[1])+a[0]; if((x0>=xx2)&&(x0<=dx2)&&(x0>=xx1)&&(x0<=dx1)) return 1; return 0; } else\\如果线段的斜率不存在 if((a[0]>=xx2)&&(a[0]<=dx2))\\如果垂线段的横坐标不在矩形框外 if((xy1<=dy2)&&(dy1>=xy2)) return 1; else return 0; else return 0; } int main() { int n,i,j,k,a[8]; scanf("%d",&n); for(i=0;i<n;i++) {for(j=0;j<8;j++) scanf("%d",&a[j]); k=tt(a); if(k==0) printf("F\n"); else printf("T\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator