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

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 10 010 010 105 42 1

Output

2

Input

5 55 106 18 6-6 -77 -15 -110 -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;
}

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

时间: 2024-08-26 11:17:44

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

[CodeForces]CodeForces - 13D 几何 思维

大致题意: 给出N个红点和M个蓝点,问可以有多少个红点构成的三角形,其内部不含有蓝点 假设我们现在枚举了一条线段(p[i],p[j]),我们可以记录线段下方满足(min(p[i].x,p[j].x)<x<=max(p[i].x,p[j].x) 的数量  时间复杂度为O(N*N*M) 那么我们就可以枚举三角形O(1)判断三角形内有无红点. 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4

向量法求三角形垂点

假设一个三角形,如图所示,求垂线与边的交点P点坐标? 方法:通过向量点乘来获取P点在线段AC的比例,然后求出P的坐标. 步骤:1. AB*AC = |AB|*|AC|*cosθ 2. |AB|*cosθ = |AP| 3. 将1中的|AB|*cosθ替换为|AP|得到:AB*AC = |AP|*|AC| 4. 解得|AP|= (AB*AC)/|AC| 5. P在AB中的比例 k=|AP|/|AC|

可鉴别共同向量法

·1.协方差与散布矩阵的意义 [尊重原创,转载请注明出处]http://blog.csdn.net/guyuealian/article/details/68922981 1)散布矩阵(散度矩阵/scatter matrix)前乘以系数1/(n-1)就可以得到协方差矩阵了,样本的协方差矩阵乘以n-1倍即为散布矩阵,n表示样本的个数,散布矩阵的大小由特征维数d决定,是一个为d×d 的半正定矩阵. 2) 关系:散度矩阵=类内离散度矩阵=类内离差阵=协方差矩阵×(n-1)   n表示样本个数 3)  

Codeforces 10C Digital Root 法冠军

主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<string> #include<stdlib.h> #include<algorithm> using nam

用射线法实现判断点是否在多边形内部

最近工作中遇到了这个问题,检索之后发现这种实现方式挺有意思的,无论是凸多边形还是凹多边形都可以判断. 射线法是用被测点向任意方向(通常为了好算,使其射向右侧)做一条射线,判断射线与多边形的交点.如果交点的数量为奇数,则被测点在多边形内:如果交点的数量为偶数,则被测点在多边形以外. 期间,有些特殊情况需要判断,比如: 1. 射线刚好经过凸多边形两条相邻边的交点上的情况会导致重复判断: 2.射线和多边形的边重合的情况. 先上js代码. function isDotInPolygon(point, p

正余弦定理证明

前言 正弦定理证明 思路一:利用三角形的高证明正弦定理: 思路二:利用三角形的面积证明正弦定理: 思路三:向量法证明正弦定理 思路四:三角形的外接圆证明 思路五:用余弦定理证明正弦定理 待补充 余弦定理证明 原文地址:https://www.cnblogs.com/wanghai0666/p/12065731.html

Codeforces Gym 100015F Fighting for Triangles 状态压缩DP

F Fighting for Triangles Description Andy and Ralph are playing a two-player game on a triangular board that looks like the following: 1 234 5 7 86 910 11 13 14 16 1712 15 18 At each turn, a player must choose two adjacent vertices and draw a line se

Codeforces Round #249 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/435 A. Queue on Bus Stop time limit per test:1 second memory limit per test:256 megabytes It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of p

BZOJ 2299 向量(裴蜀定理)

题意:给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x,y). 实际上前四个向量能拼出(ma,nb)(m%2=n%2).后四个向量拼出(xb,ya)(x%2=y%2). 这样可以枚举这四个未知数在模二意义下的解.这两个向量相加为(ma+xb,nb+ya). 对于ma+xb=X.根据系数的奇偶性,如果有系数为奇数,可使得等式两边都减去一个数使得系数都为偶