叉积: (其值等于两向量组成的三角形的有向面积的两倍)
AXB = A.x * B.y - A.y * B.x
Vector Cross(Vector A, Vector B) { return(A.x * B.y - A.y * B.x); }
性质:
AXB的符号判断(夹角小于180度)
AXB > 0 :则B在A的左边
AXB < 0 :则B在A的右边
AXB = 0 :则A和B共线,方向同向或反向
----------------------------------------------------------------------------------------------------
zju1041
问题描述:在有n个点的面上有一个给定了半径和圆心坐标的半圆,半圆可以绕圆心转动但不可以平移,求半圆最多能包含多少点,边界上的点认为在圆内。
#include <cstdio> #include <cstring> #include <cmath> const int maxn =1000 + 5; using namespace std; struct Vector { int x, y; Vector(int x=0, int y=0) : x(x), y(y) {} } f[150]; Vector operator - (Vector A, Vector B){return Vector(A.x-B.x, A.y-B.y); } int Cross(Vector A, Vector B) {return A.x*B.y - A.y*B.x; } int main() { int xx, yy; double r; Vector t; int n, i, k; while(~scanf("%d%d%lf",&t.x,&t.y,&r)) { if(r < 0) break; scanf("%d",&k); n = 0; r = r * r; while(k--) { scanf("%d%d",&xx,&yy); if( (xx-t.x)*(xx-t.x)+(yy-t.y)*(yy-t.y) <= r) { f[n].x = xx; f[n++].y = yy; } } int max = 0; for(i=0; i<n; ++i) { int totl = 0, totr = 0, j; for(j=0; j<n; ++j) { int d = Cross(f[i]-t, f[j]-t); if(d == 0) { totl++, totr++; } if(d > 0) totl++; if(d < 0) totr++; } if(totl > max) max = totl; if(totr > max) max = totr; } printf("%d\n",max); } return 0; }