题意:给定平面上N个点,问是否存在三角形,其面积为S。

思路:选择Y轴,枚举这个Y轴,面积大小只与|y-Y|有关,然后二分,具体的可以先去做BZOJ3707。

具体的:

1,先对点排序,X坐标为第一关键字,Y坐标为第二关键字,从小到大排序。

2,得到C(N,2)条直线,按照它们的斜率为关键字(叉积排序比较准确),从小到大排序。

3,二分答案,对当前直线,我们只处理线段左边(相对来说)的点,左边的点距离当前“Y轴”具有单调性。

而得到当前直线的两个点,相对于下一条直线,其相对位置会发生改变。

简单证明:(瞎证,笔画以下就知道了)

第一个直线L斜率最小,那么它左边的点,到它的相对位置大小,就是第一次排序后的大小:否则L不是斜率最小,易证。

由上一条直线,到下一条直线,对于新的“Y轴”,相对位置改变的只有上一条直线的两点:否则斜率大小有误,易证。

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
typedef long long ll;
const int maxn=;
struct Point {
int x,y;
bool operator<(const Point& B) const {
return x^B.x?x<B.x:y<B.y;
}
}P[maxn];
typedef Point Vector;
Vector operator - (Vector u, Vector v) { return (Vector){u.x-v.x,u.y-v.y}; }
Vector operator + (Vector u, Vector v) { return (Vector){u.x+v.x,u.y+v.y}; }
ll Cross(Vector u,Vector v) { return 1ll * u.x * v.y - 1ll * u.y * v.x; }
struct Segment {
int u, v;
Vector p;
bool operator<(const Segment& B) const {
return Cross(p, B.p)>;
}
}A[maxn*maxn];
int N,M,pos[maxn]; ll S;
int main() {
cin>>N>>S; S<<=1LL;
rep(i,,N) cin>>P[i].x>>P[i].y;
sort(P+,P+N+);
rep(i,,N) pos[i]=i;
rep(i,,N) rep(j,i+,N) A[++M]=(Segment){i,j,P[i]-P[j]};
sort(A+,A+M+);
rep(i,,M) {
int &a=pos[A[i].u],&b=pos[A[i].v];
Vector p=P[b]-P[a];
int l=,r=a-;
while(l<r){
int mid=(l+r+)>>;
if(abs(Cross(p,P[mid]-P[a]))>=S) l=mid;
else r=mid-;
}
if(abs(Cross(p,P[l]-P[a]))==S){
printf("Yes\n%d %d\n%d %d\n%d %d\n", P[a].x, P[a].y, P[b].x, P[b].y, P[l].x, P[l].y);
return ;
}
swap(a,b);
swap(P[a],P[b]);
}
puts("No");
return ;
}

CodeForces - 1019D(BZOJ3707圈地):Large Triangle (几何,找面积为S的三角形)的更多相关文章

  1. POJ - 2079:Triangle (旋转卡壳,求最大三角形)

    Given n distinct points on a plane, your task is to find the triangle that have the maximum area, wh ...

  2. 【codeforces 766B】Mahmoud and a Triangle

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. codeforces 558B. Amr and The Large Array 解题报告

    题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...

  4. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

  5. Codeforces Round #239 (Div. 2) C. Triangle

    time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard o ...

  6. Codeforces Round #512 D - Vasya and Triangle

    D - Vasya and Triangle #include<bits/stdc++.h> using namespace std; #define LL long long LL gc ...

  7. A. Srdce and Triangle 几何题

    链接:https://www.nowcoder.com/acm/contest/104/A来源:牛客网 题目描述 Let  be a regualr triangle, and D is a poin ...

  8. [CF1019D]Large Triangle[极角排序+二分]

    题意 给出平面上 \(n\) 个点 \((x_i, y_i)\),问是否存在三个点构成的三角形的面积恰好为 \(S\) ,有的话,输出任意一组解即可. \(n\leq 2000\) 分析 BZOJ37 ...

  9. CodeForces - 1017E :The Supersonic Rocket (几何+KMP,判定凸包是否同构)

    After the war, the supersonic rocket became the most common public transportation. Each supersonic r ...

随机推荐

  1. Devexpress GridView 常用操作总结

    一:Clone返回新的 DataTable Clone返回新的 DataTable,与当前的 DataTable 具有相同的架构:Copy:返回新的 DataTable,它具有与该 DataTable ...

  2. nginx日志自动切分

    #!/bin/bash NGINX_LOG_PATH=/data/nginx-/logs # 昨天 YESTERDAY=$(date -d "yesterday" +%Y-%m-% ...

  3. Chrome Native Messaging 与本地程序之间的通信

    最近项目上出现了web打印不稳定的问题,师父决定web调用本地打印程序,在查阅了相关资料和加了几个相关群咨询后得知新版的chrome不支持NNAPI了,最好用Native Messaging来处理,经 ...

  4. zookeeper curator CRUD

    目录 Curator客户端的基本操作 写在前面 1.1.1. Curator客户端的依赖包 1.1.2. Curator 创建会话 1.1.3. CRUD 之 Create 创建节点 1.1.4. C ...

  5. Redis通过PUBLISH / SUBSCRIBE 等命令实现了订阅与发布模式

    # 切换目录 [root@localhost /]# cd /opt/redis-4.0.10 # 启动客户端 -p 指定端口 [root@localhost ~]# redis-cli -p 638 ...

  6. Js 抱错:::SyntaxError: identifier starts immediately after numeric literal

    SyntaxError: identifier starts immediately after numeric literal 今天写了个onclick()方法,有这样的一个变量4028b88161 ...

  7. CentOS7.x 报错 There are no enabled repos.

    地址 :http://mirrors.163.com/centos/7/os/x86_64/Packages/   wget http://mirrors.163.com/centos/7/os/x8 ...

  8. IDEA main方法自动补全(转发:http://blog.csdn.net/zjx86320/article/details/52684601)

    最近刚从Eclipse转到IDEA,各种学习丫,IDEA里的main方法是不能自动补齐的,肿么办呢? 1.首先,点击File-->Settings-->Editor-->Live T ...

  9. vim vimdiff diff 使用及命令

    vim: vim 从 vim7 开始加入了多标签切换的功能, 相当于多窗口. 之前的版本虽然也有多文件编辑功能, 但是总之不如这个方便啦.用法::tabnew [++opt选项] [+cmd] 文件  ...

  10. 使用Imagemagick批量加水印缩小图片的脚本

    安装Imagemagick首先要安装Imagemagick 本文HTML永久地址 doc CentOS上安装 yum install ImageMagick -yDebian上安装 apt-get i ...