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 ...
随机推荐
- 请写一个python逻辑,计算一个文件中的大写字母数量
import os os.chdir(r'C:\Users\Administrator\Desktop')#os.chdir切换到指定目录 with open('a.txt') as today: c ...
- swift的值类型和引用类型
前言 最近在学设计模式中,发现 Swift 中的 struct,class 以及 enum 在一般的使用中能够做到互相替换,因此探究其背后的逻辑就十分有必要.而这一问题又引出了 Swift 中的值类型 ...
- Link
GNU/Linux, Bash, C, PHP, Perl, JavaScript, Vim, Git http://blog.sanctum.geek.nz/about 中文數學詞典 http: ...
- Vosio秘钥
C2FG9-N6J68-H8BTJ-BW3QX-RM3B32NYF6-QG2CY-9F8XC-GWMBW-29VV8FJ2N7-W8TXC-JB8KB-DCQ7Q-7T7V3VXX6C-DN3HQ-3 ...
- VMWare虚拟机安装步骤
VMWare虚拟机安装 如果以前安装过VMware,则先检查是否卸载干净(注册表等) 一.首先下载VMware Workstation Pro,在这里提供一个下载链接:https://www.nocm ...
- python之使用__future__(解决版本不同,不兼容问题)
Python的新版本会引入新的功能,但是,实际上这些功能在上一个老版本中就已经存在了.要“试用”某一新的特性,就可以通过导入__future__模块的某些功能来实现. 例如,Python 2.7的整数 ...
- linux中获取堆栈空间大小的方法
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include < ...
- INSPIRED启示录 读书笔记 - 第34章 恐惧、贪婪、欲望
消费者购买产品大多源于情感需求 企业级消费者出于恐惧和贪婪购买产品:如果不买这款产品,竞争对手会超过我,黑客会攻破我的防火墙,客户将弃我而去:如果买了,会赚得更多,省得更多 大众消费者购买产品的原因更 ...
- Docker 监控平台Prometheus
Prometheus 是一个强大的监控平台,提供了监控数据搜集.存储.处理.可视化和告警一套完整的解决方案. 官方网站:https://prometheus.io
- MongoDB快速入门(一)
MongoDB是一个跨平台,面向文档的数据库,提供高性能,高可用性和易于扩展.MongoDB是工作在集合和文档上一种概念. 数据数 数据库是一个集合的物理容器.每个数据库获取其自己设定在文件系统上的文 ...