题意:给定平面上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. Java 学习 day09

    01-面向对象(内部类访问规则) package myFirstCode; /* 内部类的访问规则: 1. 内部类可以直接访问外部类的成员,包括私有private. 之所以可以直接访问外部类中的成员, ...

  2. QQpet exploratory park(DP)

    QQpet exploratory park Today, more and more people begin to raise a QQpet. You can get a lot of plea ...

  3. Jeecms 防xss处理原理

    Web.xml配置过滤器,并指的要过滤和替换的字符: 过滤器的filter方法,对传入的HttpServletRequest对象进行了修改 具体过滤在XssHttpServletRequestWrap ...

  4. linux基础part2

    linux基础 一.linux基础命令 1.pwd:用来显示当前目录位置 2.cd:用来切换目录位置.(eg:cd...cd../...cd-.cd~) 3.ls:用来查看目录或文件信息(eg:ls ...

  5. Redis缓存全自动安装shell脚本

    我只是把命令放到shell文件中了,方便安装,代码如下: #!/bin/bash # shell的执行选项: # -n 只读取shell脚本,但不实际执行 # -x 进入跟踪方式,显示所执行的每一条命 ...

  6. 每天一个Linux命令(22)find命令_命令详解

        find命令的一些常用参数的常用实例和用时的注意事项.     实例:     (1)-name参数: 1)[sunjimeng@localhost home]$ find ~ -name & ...

  7. 【leetcode刷题笔记】Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 题解:要求不用乘除和取模运算实现两个数的除法. ...

  8. table-cell笔记

    display:table-cell可将元素设为类似于table的td一样的布局,在垂直居中.两行自适应布局.等高布局下有很高的利用价值 详见: http://www.zhangxinxu.com/w ...

  9. python内置方法补充bin

    bin(x) 英文说明:Convert an integer number to a binary string. The result is a valid Python expression. I ...

  10. Eclipse快捷键与Notepad++ 快捷建冲突的问题

    notepad++添加了zen coding插件以后,notepad++默认的快捷键中Alt+/也是其快捷键中的一个,表示toggle comment,而用myeclipce或eclipse的朋友都知 ...