[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)判断三角形内有无红点。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 5000006
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
#define fir first
#define sec second
#define it_s_too_hard main
#define I_can_t_solve_it solve
//const long long inf=1LL<<62;
const int inf=1e9+;
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
inline int dcmp(ld x){ if(fabs(x)<=eps) return ; return x<?-:;}
inline int scan(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline ll scan(ll x){
int f=;char ch=getchar();x=;
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct Point{
int x,y;
Point(int x=,int y=):x(x),y(y) {}
Point operator - (const Point &a)const { return Point(x-a.x,y-a.y);}
Point operator * (const ll &a)const{return Point(x*a,y*a); }
Point operator + (const Point &a)const{return Point(x+a.x,y+a.y);}
bool operator == (const Point &a)const{ return dcmp(x-a.x)== && dcmp(y-a.y)==;}
bool operator < (const Point &a)const{if(x==a.x) return y<a.y;return x<a.x;}
void read(){scanf("%d%d",&x,&y);}
void out(){cout<<x<<" "<<y<<endl;}
};
double Dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
}
double dis(Vector a){
return sqrt(Dot(a,a));
}
ll Cross(Vector a,Vector b){
return a.x*1LL*b.y-a.y*1LL*b.x;
}
bool chk(Point p1,Point p2,Point p3,Point p){
return abs(Cross(p2-p,p1-p))+abs(Cross(p3-p,p2-p))+abs(Cross(p1-p,p3-p))==abs(Cross(p2-p1,p3-p1));
}
int n,m;
Point p[],q[];
int mp[][];
void solve(){
n=scan();m=scan();
met(mp,);
For(i,,n-) p[i].read();
For(i,,m) q[i].read();
sort(p,p+n);
For(i,,n-){
For(j,i+,n-){
if(p[i].x==p[j].x) continue;
For(k,,m){
if(q[k].x>p[i].x && q[k].x<=p[j].x && Cross(q[k]-p[j],p[i]-p[j])<) mp[i][j]++;
}
}
}
int ans=;
For(i,,n-){
For(j,i+,n-){
For(k,j+,n-){
int c1=mp[i][j],c2=mp[j][k],c3=mp[i][k];
if(c1+c2==c3) ans++;
}
}
}
cout<<ans<<endl;
}
int it_s_too_hard(){
int t=;
For(i,,t){
I_can_t_solve_it();
}
return ;
}
蒻菜代码
[CodeForces]CodeForces 13D 几何 思维的更多相关文章
- Codeforces Codeforces Round #484 (Div. 2) E. Billiard
Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/proble ...
- Codeforces Codeforces Round #484 (Div. 2) D. Shark
Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D ...
- Codeforces Round #512 (Div. 2) D. Vasya and Triangle(几何+思维)
题目 题意: 给出 n,m,k ,让你在长为 n,宽为 m 的坐标系里构建一个三角形,使得面积= n*m/k.如果存在,输出“YES”,输出三角形三个顶点的坐标: 如果不存在,输出“NO”. 思路: ...
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
随机推荐
- Netty接收HTTP文件上传及文件下载
文件上传 这个处理器的原理是接收HttpObject对象,按照HttpRequest,HttpContent来做处理,文件内容是在HttpContent消息带来的. 然后在HttpContent中一个 ...
- Jekens 配置多项目SCM GitLab+Jenkins持续集成环境
参考: 搭建GitLab+Jenkins持续集成环境图文教程 https://blog.csdn.net/ruangong1203/article/details/73065410 Jenkins中配 ...
- 轻松使用div模拟select下拉菜单
没有办法,平时不是万不得已我是不喜欢去模拟各类控件的,一个是麻烦,二个是对性能也有些影响,还是原生的来的实在.老板昨天发话,必须模拟赶紧的,老外最喜欢简洁干净的风格,说的貌似都很在理的样子,业务部也是 ...
- Google推荐的15条HTML 5代码军规----来看看你知道几个,我一个都不知道。。。
Google规范的原文链接大家可以访问:http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml 1.协议头: 建议在指向图 ...
- Linux/Unix 下自制番茄钟
习惯使用番茄工作法,在Linux上工作时也需要一个番茄钟. 安装一个Linux下番茄钟工作软件? 其实根本没必要,我们可以用Linux下经典的at命令实现一个简单的番茄钟. 安装AT 一般Linux基 ...
- c++ new 和delete
c++中new和delete的使用方法 new和delete运算符用于动态分配和撤销内存的运算符 new用法: 1. 开辟单变量地址空间 1)new int; //开辟一个存放数组的存储空间 ...
- ORB_SLAM2 源码阅读 ORB_SLAM2::Initializer
ORB_SLAM2::Initializer 用于单目情况下的初始化. Initializer 的构造函数中传入第一张影像,这张影像被称作 reference frame(rFrame).在获得第二张 ...
- 简单对象List自定义属性排序
<body> <div> sort()对数组排序,不开辟新的内存,对原有数组元素进行调换 </div> <div id="showBox" ...
- 【Python学习笔记】使用Python进行T检验
使用Python进行T检验 所需要用到的第三方库有scipy. 均可以通过pip直接安装. pip install scipy numpy 引入第三方库 from scipy import stats ...
- win、mac系统配置本地电脑ip为域名教程
win系统: 如何修改hosts文件 主机文件原内容如下: #Copyright(c)1993-2009 Microsoft Corp. # #这是Windows的Microsoft TCP / IP ...