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=;
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=; scanf("%d%d",&N,&M);
a[].x=-1e9-; a[].y=-1e9-;
rep(i,,N) scanf("%d%d",&a[i].x,&a[i].y);
rep(i,,M) scanf("%d%d",&b[i].x,&b[i].y);
rep(i,,N) rep(j,,N){
if(i==j||det(a[],a[i],a[j])<) continue;
rep(k,,M)
if(det(a[],a[j],b[k])<=&&det(a[j],a[i],b[k])<=&&det(a[i],a[],b[k])<=)
dp[i][j]++;
dp[j][i]=-dp[i][j];
}
rep(i,,N)
rep(j,i+,N)
rep(k,j+,N)
ans+=(dp[i][j]+dp[j][k]+dp[k][i]==);
printf("%d\n",ans);
return ;
}

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

  1. Codeforces 528E Triangles 3000 - 计算几何

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...

  2. Codeforces 15E Triangles 【组合计数】

    Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...

  3. [CodeForces]CodeForces 13D 几何 思维

    大致题意: 给出N个红点和M个蓝点,问可以有多少个红点构成的三角形,其内部不含有蓝点 假设我们现在枚举了一条线段(p[i],p[j]),我们可以记录线段下方满足(min(p[i].x,p[j].x)& ...

  4. Codeforces 15E Triangles - 组合数学

    Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...

  5. Codeforces 1060E(思维+贡献法)

    https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...

  6. Codeforces 10C Digital Root 法冠军

    主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...

  7. HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  8. Codeforces Round #313 C. Gerald&#39;s Hexagon(放三角形)

    C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

    F Fighting for Triangles Description Andy and Ralph are playing a two-player game on a triangular bo ...

随机推荐

  1. 使用idea2016导出web项目war包

    第一步配置Web Application:Exploded(已经配置的可以跳到第二步): 打开project structure(默认的快捷键是Ctrl+Alt+Shift+S),依次选择Artifa ...

  2. VSCode eslint校验 tab改为2个空格

    修改:.eslintrc.json

  3. 【Head First Servlets and JSP】笔记14:session再探 & Listener示例

    对于session的“CRUD” 会话迁移 别忘了HttpSessionBindingListener Listener示例 1.session的“增”与“删”——session的创建和撤销的调用主体 ...

  4. 主攻ASP.NET.4.5 MVC4.0之重生:网站更换外观皮肤界面样式

    CommonController---_Admin.cshtml SysUserRepository sysuserrepository = new SysUserRepository(); publ ...

  5. Scrapy安装方法

    Scrapy安装在Python2.7环境下 1.配置环境变量: 2.安装基础软件 4个(64位系统) 安装twisted: C:\Users\Administrator>pip  install ...

  6. 用PyDev、eclipse搭建Python开发环境

    一 Eclipse for python环境搭建 ①下载原生Eclipse,可以直接百度Eclipse,在百度软件中心下载  ②下载完后,打开软件,选择第一个安装即可  ③安装完成后,打开eclips ...

  7. eclipse异常关了,tomcat如何关

    eclipse异常关了,tomcat如何关 ? 1.bin文件夹下面有的shutdown.bat.双击即可! 2.在任务管理器里面关闭,看到javaw.exe关闭也行.            

  8. UVA 580 Critical Mass (两次dp)

    题意:一个字符串有n个位置每个位置只可能是L或者U,问你在所有可能出现的字符串中最少出现一次三个U连在一起的字符串的个数 题解:首先从左向右枚举每个位置i,保证i,i+1,i+2是U,并且i+2(不包 ...

  9. javascript 时间日期处理相加相减

    var d = new Date("2008/04/15"); d.setMonth(d.getMonth() + 1 + 1);//加一个月,同理,可以加一天:getDate() ...

  10. MVP实战心得—封装Retrofit2.0+RxAndroid+RxBus

    响应式编程框架,rxjava的扩展,很爽的链式编程 魅力在于对数据的处理,与线程切换的灵活性. 用来处理异步操作(Lambda表达式不会用.用Lambda表达式代码会更少,但不会的人会看不懂代码.不是 ...