洛谷P4250 [SCOI2015]小凸想跑步(半平面交)
题面
题解
设\(p\)点坐标为\(x_p,y_p\),那么根据叉积可以算出它与\((i,i+1)\)构成的三角形的面积
为了保证\(p\)与\((0,1)\)构成的面积最小,就相当于它比其它所有的三角形构成的面积都要小。如果\(p\)与\((0,1)\)构成的面积比\((i,i+1)\)小,代入叉积计算公式,有
\]
然后我们知道对于形如\(Ax+By+C<0\)的线性规划,向量\((-B,A)\)代表的就是这个线性规划的半平面
直接半平面交求解就行了
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=2e5+5;const double eps=1e-10;
inline int sgn(R double x){return x<-eps?-1:x>eps;}
inline double abs(R double x){return x<-eps?-x:x;}
struct node{
double x,y;
inline node(){}
inline node(R double xx,R double yy):x(xx),y(yy){}
inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
inline double operator *(const node &b)const{return x*b.y-y*b.x;}
inline node operator ^(const double &b)const{return node(x*b,y*b);}
}p[N],s[N];
struct Line{
node p,v;double ang;
inline Line(){}
inline Line(R node pp,R node vv):p(pp),v(vv){ang=atan2(v.y,v.x);}
inline bool operator <(const Line &b)const{return sgn(ang-b.ang)?sgn(ang-b.ang)<0:sgn(v*(b.p-p))<0;}
friend node cross(const Line &a,const Line &b){return a.p+(a.v^(b.v*(b.p-a.p)/(b.v*a.v)));}
inline bool Right(R node &b){return sgn(v*(b-p))<0;}
}L[N],q[N];
int n,m,tot,h,t;double area,res;
void HalfPlane(){
sort(L+1,L+1+m);
q[h=t=1]=L[1];
fp(i,2,m)if(sgn(L[i].ang-L[i-1].ang)){
while(h<t&&L[i].Right(p[t-1]))--t;
while(h<t&&L[i].Right(p[h]))++h;
q[++t]=L[i];
if(h<t)p[t-1]=cross(q[t],q[t-1]);
}
while(h<t&&q[h].Right(p[t-1]))--t;
if(t-h+1<=2)return;
p[t]=cross(q[t],q[h]),p[t+1]=p[h];
fp(i,h,t)res+=p[i]*p[i+1];
}
int main(){
// freopen("testdata.in","r",stdin);
n=read();
fp(i,0,n-1)s[i].x=read(),s[i].y=read();
s[n]=s[0];
fp(i,1,n-1)area+=(s[i]-s[0])*(s[i+1]-s[0]);
fp(i,0,n-1)L[++m]=Line(s[i],s[i+1]-s[i]);
fp(i,1,n-1){
double a=s[0].y-s[1].y+s[i+1].y-s[i].y;
double b=s[1].x-s[0].x-s[i+1].x+s[i].x;
double c=s[0].x*s[1].y-s[1].x*s[0].y+s[i+1].x*s[i].y-s[i].x*s[i+1].y;
L[++m]=Line(sgn(b)?node(0,-c/b):node(-c/a,0),node(-b,a));
}
HalfPlane();
printf("%.4lf\n",res/area);
return 0;
}
洛谷P4250 [SCOI2015]小凸想跑步(半平面交)的更多相关文章
- 【BZOJ4445】[SCOI2015]小凸想跑步(半平面交)
[BZOJ4445][SCOI2015]小凸想跑步(半平面交) 题面 BZOJ 洛谷 题解 首先把点给设出来,\(A(x_a,y_a),B(x_b,y_b),C(x_c,y_c),D(x_d,y_d) ...
- 【BZOJ4445】[Scoi2015]小凸想跑步 半平面交
[BZOJ4445][Scoi2015]小凸想跑步 Description 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸n边形,N个顶点按照逆时针从0-n-l编号.现 ...
- [SCOI2015]小凸想跑步
题目描述 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸 n 边形, nn 个顶点按照逆时针从 0 ∼n−1 编号.现在小凸随机站在操场中的某个位置,标记为p点.将 p ...
- BZOJ 4445 [Scoi2015]小凸想跑步:半平面交
传送门 题意 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸 $ n $ 边形,$ n $ 个顶点 $ P_i $ 按照逆时针从 $ 0 $ 至 $ n-1 $ 编号. ...
- [bzoj4443] [loj#2006] [洛谷P4251] [Scoi2015]小凸玩矩阵
Description 小凸和小方是好朋友,小方给小凸一个 \(N \times M\)( \(N \leq M\) )的矩阵 \(A\) ,要求小秃从其中选出 \(N\) 个数,其中任意两个数字不能 ...
- bzoj 4445 [SCOI2015] 小凸想跑步
题目大意:一个凸包,随机一个点使得其与前两个点组成的面积比与其他相邻两个点组成的面积小的概率 根据题意列方程,最后求n条直线的交的面积与原凸包面积的比值 #include<bits/stdc++ ...
- BZOJ4445: [Scoi2015]小凸想跑步
裸半平面交. 记得把P0P1表示的半平面加进去,否则点可能在多边形外. #include<bits/stdc++.h> #define N 100009 using namespace s ...
- BZOJ4445 SCOI2015小凸想跑步(半平面交)
考虑怎样的点满足条件.设其为(xp,yp),则要满足(x0-xp,y0-yp)×(x1-xp,y1-yp)<=(xi-xp,yi-yp)×(xi+1-xp,yi+1-yp)对任意i成立.拆开式子 ...
- 2018.10.15 bzoj4445: [Scoi2015]小凸想跑步(半平面交)
传送门 话说去年的省选计算几何难度跟前几年比起来根本不能做啊(虽然去年考的时候并没有学过计算几何) 这题就是推个式子然后上半平面交就做完了. 什么? 怎么推式子? 先把题目的概率转换成求出可行区域. ...
随机推荐
- docker swarm test
consul: 192.168.111.111: docker run -d -p 8500:8500 --name=consul progrium/consul -server -bootstrap ...
- WSAEvent
[WSAEvent] 1.WSACreateEvent.创建WSA事件. 2.WSAEventSelect. lNetworkEvents [in] A bitmask that specifies ...
- Emacs及扩展配置
Emacs及扩展配置 Table of Contents 1. 动机之反思 2. 它山之石 3. 扩展的管理 4. 我额外安装的通用扩展(在purcell基础上) 5. LaTex相关的问题和配置 6 ...
- UILabel的空格不支持tab键
今天使用模拟器测试,发现有个UITableViewCell的detailTextLabel没有完全显示字符串,结尾是省略号,字符串的值中间显示有空格,如 'Test 01'显示为'Te...' det ...
- Write File
Write to File with C++ #include <iostream.h> #include <fstream.h> int main() { const cha ...
- JavaScript Math.floor() 方法
定义和用法: floor() 方法可对一个数进行下舍入. 语法: Math.floor(x); x:必须参数,可以是任意数值或表达式: 返回值: 小于等于 x,且与 x 最接近的整数. 说明: flo ...
- CoreImage
[CoreImage] CIContext is an object through which Core Image draws the results produced by a filter. ...
- Android Gson 操作
JSON序列化后的数据不带类名与名命空间,所以这两个服务端跟客户端可以不对应,需要保证字段对应即可 Asp.net MVC端 using System; using System.Collection ...
- [GO]redis的连接
package main import ( "github.com/garyburd/redigo/redis" "fmt" ) var pool *redis ...
- Adobe Photoshop CC 2015安装激活教程
Adobe Photoshop CC 2015安装激活教程(附序列号) Adobe Photoshop CC 2015是Adobe针对旗下的创意云Creative Cloud 套装推出了2015年年度 ...