大致题意:

    给出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 几何 思维的更多相关文章

  1. Codeforces Codeforces Round #484 (Div. 2) E. Billiard

    Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/proble ...

  2. Codeforces Codeforces Round #484 (Div. 2) D. Shark

    Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D ...

  3. Codeforces Round #512 (Div. 2) D. Vasya and Triangle(几何+思维)

    题目 题意: 给出 n,m,k ,让你在长为 n,宽为 m 的坐标系里构建一个三角形,使得面积= n*m/k.如果存在,输出“YES”,输出三角形三个顶点的坐标:  如果不存在,输出“NO”. 思路: ...

  4. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  5. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  6. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  7. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  8. Codeforces 675C Money Transfers 思维题

    原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...

  9. 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 ...

随机推荐

  1. Java并发编程原理与实战三十二:ForkJoin框架详解

    1.Fork/Join框架有什么用呢? ------->Fork使用来切分任务,Join是用来汇总结果.举个简单的栗子:任务是1+2+3+...+100这个任务(当然这个任务的结果有好的算法去做 ...

  2. Kafka安装验证及其注意

    一.Zookeeper 配置文件说明: # the directory where the snapshot is stored. dataDir=/tmp/zookeeper # the port ...

  3. spring框架学习(八)spring管理事务方式之注解配置

    1.DAO AccountDao.java package cn.mf.dao; public interface AccountDao { //加钱 void increaseMoney(Integ ...

  4. [php]mysql操作流程

    这种是比较老的一种mysql连接方法 1.连接数据库 $this->con = mysql_connect($this->host, $this->user, $this->p ...

  5. 【Hadoop】Win7上搭建Hadoop开发环境,方法一

    在Win7上,编写hadoop程序 操作系统:win7 hadoop版本:CDH3u6 1.下载安装JDK,以及Eclipse 2.新建JAVA Project 3.去cloudera网站下载hado ...

  6. POJ 2230 Watchcow && USACO Watchcow 2005 January Silver (欧拉回路)

    Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to wal ...

  7. Nginx配置location及rewrite规则

    Nginx配置location及rewrite规则 示例: location  = / {   # 精确匹配 / ,主机名后面不能带任何字符串   [ configuration A ] } loca ...

  8. Servlet笔记6--Servlet程序改进

    第一步改进,GenericServlet: 我们目前所有放入Servlet类直接实现了javax.servlet.Servlet接口,但是这个接口中有很多方法是目前不需要的,我们可能只需要编写serv ...

  9. Hibernate5笔记8--Hibernate事务相关内容

    Hibernate事务相关内容: (1) 事务四大特性(简称ACID): (1)原子性(Atomicity) 事务中的全部操作在数据库中是不可分割的,要么全部完成,要么均不执行. (2)一致性(Con ...

  10. Cesium entity click

    var url = 'http://202.107.245.51:81/user/dev/api/v2/sql?rows_per_page=40&page=0&sort_order=a ...