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
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=;
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(向量法:问多少个蓝点三角形内部无红点)的更多相关文章
- Codeforces 528E Triangles 3000 - 计算几何
题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...
- Codeforces 15E Triangles 【组合计数】
Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...
- [CodeForces]CodeForces 13D 几何 思维
大致题意: 给出N个红点和M个蓝点,问可以有多少个红点构成的三角形,其内部不含有蓝点 假设我们现在枚举了一条线段(p[i],p[j]),我们可以记录线段下方满足(min(p[i].x,p[j].x)& ...
- Codeforces 15E Triangles - 组合数学
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Codeforces 10C Digital Root 法冠军
主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- Codeforces Round #313 C. Gerald's Hexagon(放三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
随机推荐
- MySql安装成功后命令行进行必要的配置
1.1 首次用命令行登录 用zip方式安装成功mysql,并通过net start mysql 命令正常启动mysql服务后,打开dos命令行窗口,输入“mysql -uroot -p”或“mysql ...
- iOS CMTimeMake 和 CMTimeMakeWithSeconds 学习
CMTime是专门用于标识电影时间的结构体,通常用如下两个函数来创建CMTime (1)CMTimeMake CMTime CMTimeMake ( int64_t value, //表示 当前视频播 ...
- 通过调节坐标进行jfree图的放大缩小
http://blog.csdn.net/lt1983lt/article/details/5665085 import Java.awt.BorderLayout;import java.awt.C ...
- Struts2笔记02——Struts2 概述(转)
原始内容:https://www.tutorialspoint.com/struts_2/basic_mvc_architecture.htm Struts2是基于MVC设计模式的一种流行.成熟的We ...
- P4340 [SHOI2016]随机序列
题目 P4340 [SHOI2016]随机序列 思维好题 做法 是否觉得水在于你是否发现加减是会抵消的,所以我们只用考虑乘的部分 一块乘只能前面无号(也就是前缀形式)才统计,所以用线段树维护区间前缀乘 ...
- Linux设置默认启动命令行,而不是图形界面
无论是作为上线的服务器还是开发中的虚拟机来说,都是没有必要启动图形界面的,而图形界面占用的内存还是很大的.枫竹梦本文就介绍如何设置来默认启动命令行. 其实就是设置系统的启动级别. CentOS的设置 ...
- MySQL数据库基本操作(三)
MySQL补充: mysql是关系型数据库,关系数据库,是建立在关系模型基础上的数据库,现实世界中的各种实体,以及实体之间的各种联系,均用关系模型(table)来表示.#关系模型就是指二维表格模型,因 ...
- MIPI DBI\DPI\DSI简介【转】
本文转载自:http://blog.csdn.net/longxiaowu/article/details/24249971 (1)DBI接口 A,也就是通常所讲的MCU借口,俗称80 system接 ...
- Android LCD(二):常用接口原理篇【转】
本文转载自:http://blog.csdn.net/xubin341719/article/details/9125799 关键词:Android LCD TFT TTL(RGB) LVDS E ...
- avaweb学习总结(八)——HttpServletResponse对象(二)
一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedImage类,