杭电acm1086

S(abc) = (|ab|*|ac|*sinΘ) / 2 = |ab| × |ac| / 2//叉积

#include <stdio.h>

struct point {
	double x1, y1, x2, y2;
}buf[101];

int judge(int i, int j) {
	//叉积
	int f1=0,f2=0;  
    double acd=(buf[i].x1-buf[j].x1)*(buf[i].y1-buf[i].y2)-(buf[i].x1-buf[i].x2)*(buf[i].y1-buf[j].y1);  
    double bcd=(buf[i].x1-buf[j].x2)*(buf[i].y1-buf[i].y2)-(buf[i].x1-buf[i].x2)*(buf[i].y1-buf[j].y2);  
    if(acd*bcd<=0)  
    	f1=1;  
    double cab=(buf[j].x1-buf[i].x1)*(buf[j].y1-buf[j].y2)-(buf[j].x1-buf[j].x2)*(buf[j].y1-buf[i].y1);  
    double dab=(buf[j].x1-buf[i].x2)*(buf[j].y1-buf[j].y2)-(buf[j].x1-buf[j].x2)*(buf[j].y1-buf[i].y2);  
    if(cab*dab<=0)  
    	f2=1;  
    if((f1+f2)==2)  
    	return 1;  
      
    return 0;  
}

int main() {
	
	int n, i, j, ans;
	while(~scanf("%d", &n) && n) {
		
		ans = 0;
		for(i=0; i<n; i++)
			scanf("%lf%lf%lf%lf", &buf[i].x1, &buf[i].y1,
					&buf[i].x2, &buf[i].y2);
					
		for(i=0; i<n-1; i++)
			for(j=i+1; j<n; j++)
				if(judge(i, j))
					ans ++;
		
		printf("%d\n", ans);
	}
	
	return 0;
}


posted @ 2015-12-16 13:18  StevenLuke  阅读(113)  评论(0编辑  收藏  举报