首页 > 其他 > 详细

CodeForces - 13D :Triangles(向量法:问多少个蓝点三角形内部无红点)

时间:2018-09-11 11:54:55      阅读:140      评论:0      收藏:0      [点我收藏+]

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

Input
4 1
0 0
10 0
10 10
5 4
2 1
Output
2
Input
5 5
5 10
6 1
8 6
-6 -7
7 -1
5 -1
10 -4
-10 -8
-10 5
-2 -8
Output
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\n",ans);
    return 0;
}

 

CodeForces - 13D :Triangles(向量法:问多少个蓝点三角形内部无红点)

原文:https://www.cnblogs.com/hua-dong/p/9626641.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!