本文主要是介绍FZU 2148(计算几何)叉积模板,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:点击打开链接
题目分析:凸四边形个数判断,枚举法。
Sacb+Sabd+Sacd=Sbcd;
则为凹多边形。
题目总结:i,j,k,l一多,j++写成i++ wa了好几炮
此题可为为模板了
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;
const double eps = 1e-8;
struct point{int x, y;point (int x=0, int y=0):x(x),y(y){};
};
point data[50];
typedef point vector;
vector operator + (vector A, vector B){ return vector(A.x+B.x, A.y+B.y); }
vector operator - (vector A, vector B){ return vector(A.x-B.x, A.y-B.y); }
vector operator * (vector A, double p){ return vector(A.x*p, A.y*p); }
vector operator / (vector A, double p){ return vector(A.x/p, A.y/p); }
bool operator < (const point &a, const point &b){return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
int dcmp( double x){if(fabs(x)<eps) return 0;else return x<0 ?-1 :1;
}
bool operator == (const point&a, const point&b){return dcmp(a.x-b.x)==0 &&dcmp(a.y-b.y)==0;
}
double cross(vector a, vector b) { return a.x*b.y- a.y*b.x; }
double area(point a, point b, point c) {return cross(b-a, c-a);}bool solve(point a, point b, point c, point d){double s1,s2,s3,s4;s1 = fabs(area(a,b,c));s2 = fabs(area(a,b,d));s3 = fabs(area(b,c,d));s4 = fabs(area(a,c,d));if((s1+s2+s3-s4==0)||(s1+s2+s4-s3==0)||(s1+s4+s3-s2==0)||(s4+s2+s3-s1==0))return false;return true;
}
int main()
{int t,tt=1, n, ans, i, j, k, l;cin>>t;while(t--){ans=0;cin>>n;for (i=1; i<=n; i++)scanf("%d%d",&data[i].x, &data[i].y);for(i=1; i<=n; i++)for(j=i+1; j<=n; j++)for(k=j+1; k<=n; k++)for(l=k+1; l<=n; l++)if(solve(data[i], data[j], data[k], data[l]))ans++;printf("Case %d: %d\n",tt++, ans);}return 0;
}
这篇关于FZU 2148(计算几何)叉积模板的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!