CodeForces - 1019D(BZOJ3707圈地):Large Triangle (几何,找面积为S的三角形)
题意:给定平面上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的三角形)的更多相关文章
- POJ - 2079:Triangle (旋转卡壳,求最大三角形)
Given n distinct points on a plane, your task is to find the triangle that have the maximum area, wh ...
- 【codeforces 766B】Mahmoud and a Triangle
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces 558B. Amr and The Large Array 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
- Codeforces Round #239 (Div. 2) C. Triangle
time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard o ...
- Codeforces Round #512 D - Vasya and Triangle
D - Vasya and Triangle #include<bits/stdc++.h> using namespace std; #define LL long long LL gc ...
- A. Srdce and Triangle 几何题
链接:https://www.nowcoder.com/acm/contest/104/A来源:牛客网 题目描述 Let be a regualr triangle, and D is a poin ...
- [CF1019D]Large Triangle[极角排序+二分]
题意 给出平面上 \(n\) 个点 \((x_i, y_i)\),问是否存在三个点构成的三角形的面积恰好为 \(S\) ,有的话,输出任意一组解即可. \(n\leq 2000\) 分析 BZOJ37 ...
- CodeForces - 1017E :The Supersonic Rocket (几何+KMP,判定凸包是否同构)
After the war, the supersonic rocket became the most common public transportation. Each supersonic r ...
随机推荐
- EasyDarwin开源流媒体服务器Golang版本:服务端录像功能发布
EasyDarwin开源流媒体服务器(www.easydarwin.org)现在使用Go版本实现了.最新的代码提交,已经支持了推流(或者拉流)的同时进行本地存储. 本地存储的原理,是在推流的同时启动f ...
- Mybatis sql注入问题
预编译方式,即PreparedStatement,可以防注入:#{id} <select id="getBlogById" resultType="Blog&quo ...
- zip filter map 列表生成器
map map(function, list): 就是对list 中的每一个元素都调用function函数进行处理,返回一个map的对象 list一下就可以生成一个列表 或者for循环该对象就可以输出 ...
- Django 事务
Django事务 事务是通过将一组相关操作组合为一个,要么全部成功要么全部失败的单元,可以简化错误恢复并使应用程序更加可靠.事务具有4个特性:原子性.一致性.隔离性.持久性. 默认情况下,在Djang ...
- linux环境下redis安装
本篇文章主要说明的是Linux环境下redis数据库的安装: 首先进入目标目录: 下载安装包,执行命令: wget http://download.redis.io/releases/redis-4. ...
- (转)RequireJS shim 用法说明
RequireJS中如果使用AMD规范,在使用的过程中没有太多的问题,如果加载非AMD规范的JS文件,就需要使用Require中的shim. require.config({ paths:{ jque ...
- activiti--5 -----------------Activiti 工作流 流程各个步骤所涉及到的表
ACT_RE_*: 'RE'表示repository. 这个前缀的表包含了流程定义和流程静态资源 (图片,规则,等等). ACT_RU_*: 'RU'表示runtime. 这些运行时的表,包含流程实例 ...
- 添加启动项及常用Windows+R
常用Windows+R services.msc---本地服务设置 msconfig---系统配置实用程序 mspaint--------画图板 notepad--------打开记事本 Nslook ...
- HR_ROS 节点信息
https://stackoverflow.com/questions/24638063/install-node-serialport-module-on-arm-linux https://blo ...
- 牛客小白月赛1 E 圆与三角形 【数学】
题目链接 https://www.nowcoder.com/acm/contest/85/E 思路 在三角形中,这一串东西的值恒为1 又 SIN A 的最大值 为1 所以 这串式子的最大值 就是 r ...