Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.
Input
The first line contains two non-negative integer numbers N and M (0 ≤ N ≤ 500, 0 ≤ M ≤ 500) — the number of red and blue points respectively. The following N lines contain two integer numbers each — coordinates of red points. The following M lines contain two integer numbers each — coordinates of blue points. All coordinates do not exceed 109 by absolute value.
Output
Output one integer — the number of distinct triangles with vertices in red points which do not contain any blue point inside.
Examples
4 1
0 0
10 0
10 10
5 4
2 1
2
5 5
5 10
6 1
8 6
-6 -7
7 -1
5 -1
10 -4
-10 -8
-10 5
-2 -8
7
向量法:这里写得很明了了:https://blog.csdn.net/v5zsq/article/details/79687164。。。(我还是太菜了
#include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn=510; struct point{ int x,y; point(){} }a[maxn],b[maxn]; ll det(point O,point A,point B){ return (1LL*A.x-O.x)*(B.y-O.y)-(1LL*B.x-O.x)*(A.y-O.y); } int dp[maxn][maxn]; int main() { int N,M,ans=0; scanf("%d%d",&N,&M); a[0].x=-1e9-1; a[0].y=-1e9-1; rep(i,1,N) scanf("%d%d",&a[i].x,&a[i].y); rep(i,1,M) scanf("%d%d",&b[i].x,&b[i].y); rep(i,1,N) rep(j,1,N){ if(i==j||det(a[0],a[i],a[j])<0) continue; rep(k,1,M) if(det(a[0],a[j],b[k])<=0&&det(a[j],a[i],b[k])<=0&&det(a[i],a[0],b[k])<=0) dp[i][j]++; dp[j][i]=-dp[i][j]; } rep(i,1,N) rep(j,i+1,N) rep(k,j+1,N) ans+=(dp[i][j]+dp[j][k]+dp[k][i]==0); printf("%d ",ans); return 0; }