题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望。

思路:半平面交+概率期望

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1e5+;
const double eps=1e-;
const double pi=acos(-); double dcmp(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
} struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Point& A, const Point& B)
{
return Vector(A.x+B.x, A.y+B.y);
} Vector operator - (const Point& A, const Point& B)
{
return Vector(A.x-B.x, A.y-B.y);
} Vector operator * (const Point& A, double v)
{
return Vector(A.x*v, A.y*v);
} Vector operator / (const Point& A, double v)
{
return Vector(A.x/v, A.y/v);
} double Cross(const Vector& A, const Vector& B)
{
return A.x*B.y - A.y*B.x;
} double Dot(const Vector& A, const Vector& B)
{
return A.x*B.x + A.y*B.y;
} double Length(const Vector& A)
{
return sqrt(Dot(A,A));
} Vector Rotate(Vector A,double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
} bool operator < (const Point& p1, const Point& p2)
{
return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
} bool operator == (const Point& p1, const Point& p2)
{
return p1.x == p2.x && p1.y == p2.y;
} Vector Normal(Vector A)
{
double L=Length(A);
return Vector(-A.y/L,A.x/L);
}
struct Line
{
Point P;
Vector v;
double ang;
Line() {}
Line(Point P, Vector v):P(P),v(v)
{
ang = atan2(v.y, v.x);
}
bool operator < (const Line& L) const
{
return ang < L.ang;
}
}; bool OnLeft(const Line& L, const Point& p)
{
return Cross(L.v, p-L.P) > ;
} Point GetLineIntersection(const Line& a, const Line& b)
{
Vector u = a.P-b.P;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.P+a.v*t;
} const double INF = 1e8; Point ansPoly[maxn];
int HalfplaneIntersection(vector<Line> L) //L为切割平面的直线集合,求半平面交,返回点的个数,点存在anspoly数组中
{
int n = L.size();
sort(L.begin(), L.end()); // 按极角排序
int first, last; // 双端队列的第一个元素和最后一个元素的下标
vector<Point> p(n); // p[i]为q[i]和q[i+1]的交点
vector<Line> q(n); //
q[first=last=] = L[]; //
for(int i = ; i < n; i++)
{
while(first < last && !OnLeft(L[i], p[last-])) last--;
while(first < last && !OnLeft(L[i], p[first])) first++;
q[++last] = L[i];
if(fabs(Cross(q[last].v, q[last-].v)) < eps) //
{
last--;
if(OnLeft(q[last], L[i].P)) q[last] = L[i];
}
if(first < last) p[last-] = GetLineIntersection(q[last-], q[last]);
}
while(first < last && !OnLeft(q[first], p[last-])) last--; //
if(last - first <= ) return ; //
p[last] = GetLineIntersection(q[last], q[first]); //
// 从deque复制到输出中
int index=;
for(int i = first; i <= last; i++) ansPoly[index++]=p[i];
return index;
} double PolygonArea(int n,Point *p)
{
double area=;
for(int i=; i<n-; i++)
area+=Cross(p[i]-p[],p[i+]-p[]);
return area/;
}
// vector<Line> vec;
// vec.push_back(Line(Point(0,0),Point(1,0)));
// vec.push_back(Line(Point(10000,0),Point(0,1)));
// vec.push_back(Line(Point(10000,10000),Point(-1,0)));
// vec.push_back(Line(Point(0,10000),Point(0,-1)));
// Vector v=(p[1]-p[0]);
// vec.push_back(Line((p[1]+p[0])*0.5,Normal(v)));
// v=(p[2]-p[0]);
// vec.push_back(Line((p[2]+p[0])*0.5,Normal(v)));
// int m=HalfplaneIntersection(vec);
// double ans=PolygonArea(m,ansPoly);
// printf("%.3f\n",ans/(1.0*10000*10000));
Point p[];
void CC(Point *p)
{
for(int i=; i<maxn; i++)
{
p[i].x=;
p[i].y=;
}
}
int main()
{
// freopen("in.txt","r",stdin);
double a1,a2,a3,a4,a5,a6;
a5=(5.0**)/(**-);
a2=;
while(cin>>p[].x>>p[].y>>p[].x>>p[].y>>p[].x>>p[].y>>p[].x>>p[].y)
{
CC(ansPoly);
vector<Line>vec;
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(-0.5,-0.5),Point(-,)));
int sou_num=HalfplaneIntersection(vec);
a1=PolygonArea(sou_num,ansPoly);
// cout<<"a1:"<<a1<<endl;
// cout<<"sou_num:"<<sou_num<<endl;
// CC(ansPoly);
vec.clear();
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(-0.5,-0.5),Point(,)));
int west_num=HalfplaneIntersection(vec);
// cout<<ansPoly[3].y<<endl;
a4=PolygonArea(west_num,ansPoly);
// cout<<"a4:"<<a4<<endl;
// cout<<"west_num:"<<west_num<<endl;
CC(ansPoly);
vec.clear();
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(-0.5,0.5),Point(,)));
int nor_num=HalfplaneIntersection(vec);
a6=PolygonArea(nor_num,ansPoly);
// cout<<"a6:"<<a6<<endl;
// cout<<"nor_num:"<<nor_num<<endl;
CC(ansPoly);
vec.clear();
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(p[].x,p[].y),Point(p[].x-p[].x,p[].y-p[].y)));
vec.push_back(Line(Point(0.5,0.5),Point(,-)));
int east_num=HalfplaneIntersection(vec);
a3=PolygonArea(east_num,ansPoly);
// cout<<"a3:"<<a3<<endl;
// cout<<"east_num:"<<east_num<<endl;
long double ans1,ans2,ans3,ans4,ans5,ans6;
double ans;
// anss=(5.0*a1)/(5*5*5-1)+2*(5.0*a2)/(5*5*5-1)+3*(5.0*a3)/(5*5*5-1)+4*(5.0*a4)/(5*5*5-1)+a5*5.0+6*(5.0*a6)/(5*5*5-1);
ans1=(5.0*a1)/(**-);
// cout<<"ans1:"<<ans1<<endl;
ans2=(5.0*a2)/(**-);
// cout<<"ans2:"<<ans2<<endl;
ans3=*(5.0*a3)/(**-);
// cout<<"ans3:"<<ans3<<endl;
ans4=*(5.0*a4)/(**-);
// cout<<"ans4:"<<ans4<<endl;
ans5=*a5;
// cout<<"ans5:"<<ans5<<endl;
ans6=*(5.0*a6)/(**-);
// cout<<"ans6:"<<ans6<<endl;
ans=ans1+ans2+ans3+ans4+ans5+ans6;
printf("%.10lf\n",ans);
}
return ;
}

uvalive 7331 Hovering Hornet 半平面交+概率期望的更多相关文章

  1. UVALive 4992 Jungle Outpost(半平面交判存)

    Jungle Outpost Time limit: 15.000 seconds Description There is a military base lost deep in the jung ...

  2. UVALive 4992 Jungle Outpost(半平面交)

    题意:给你n个塔(点)形成一个顺时针的凸包,敌人可以摧毁任何塔,摧毁后剩下的塔再组成凸包 在开始的凸包内选一点为主塔,保证敌人摧毁尽量多塔时主塔都还在现在的凸包内,求出最多摧毁的塔 题解:这题关键就是 ...

  3. 概率与期望详解!一次精通oi中的概率期望

    目录 基础概念 最大值不超过Y的期望 概率为P时期望成功次数 基础问题 拿球 随机游走 经典问题 期望线性性练习题 例题选讲 noip2016换教室 区间交 0-1边树求直径期望 球染色 区间翻转 二 ...

  4. 2018.10.15 bzoj4445: [Scoi2015]小凸想跑步(半平面交)

    传送门 话说去年的省选计算几何难度跟前几年比起来根本不能做啊(虽然去年考的时候并没有学过计算几何) 这题就是推个式子然后上半平面交就做完了. 什么? 怎么推式子? 先把题目的概率转换成求出可行区域. ...

  5. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

  6. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  7. 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分

    2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 959  Solved: 489[Submit][Status] ...

  8. 【CSU1812】三角形和矩形 【半平面交】

    检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...

  9. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

随机推荐

  1. Pjax介绍及在asp.net MVC3中使用pjax的简单示例

    相信很多人对ajax并不陌生,对ajax的一些优点也了如指掌,如:局部刷新改善用户体验,减少开销,让服务器和浏览器之间的响应更快等. 但是它的缺点也是很显而易见的: AJAX大量的使用了javascr ...

  2. 与wait for a undo record相关的系统卡死

    今天下班之前同事过来找我寻求帮助,说是某客户的ORACEL数据库服务器从昨天起就开始很奇怪,一个语句执行很慢很慢,好像整个系统都卡住了.      问题1:请问最近应用系统有更新过程序吗?答:没有更新 ...

  3. 关于Weblogic连接池的TestConnectionOnReserve

        由于最近某客户的系统性能比较差,所以今天又上去跟踪了一下.看了一下Default Data Cache,发现已经从10G调整到了20G,所以可以确定应该是客户的管理员已经将双机从低配置的机器切 ...

  4. JLink软件升级到4.92之后,Jlink不能用了

    JLink软件升级到4.92之后,Jlink不能用了                                                       情景描述: Jlink软件升级到4.9 ...

  5. 微信web开发者工具调试

    微信web开发者工具调试 前几天写了一篇使用fiddler调试微信端页面的,然后博友评论说使用fiddler太麻烦了,推荐使用微信web开发者工具调试微信页面,这两天弄着玩了一下,很强大.这篇文章只是 ...

  6. VS2015下的Android开发系列01——开发环境配置及注意事项

    概述 VS自2015把Xamarin集成进去后搞Android开发就爽了,不过这安装VS2015完成的时候却是长了不知道多少.废话少说进正题,VS2015安装时注意把Android相关的组件勾选安装, ...

  7. DB天气app冲刺第四天

    今天卡壳了 做得很慢.. 明天继续 换一种思路试一下吧..

  8. [转载]如何打一手好Log

    如果项目上过线的话,那你一定知道Log是多么重要. 为什么说Log重要呢?因为上线项目不允许你调试,你只能通过Log来分析问题.这时打一手好Log的重要性绝不亚于写一手好代码.项目出问题时,你要能拿出 ...

  9. ASP.net Application及Session 的start end 方法总结

    经过几天的摸索,试验,今天终于可以将Application及Session对象的Start和End方法做下总结了. Application_start: 第一个访问网站的用户会触发该方法. 通常会在该 ...

  10. HDU 2045 不容易系列之(3)—— LELE的RPG难题(递推)

    点我看题目 题意 : 中文题不解释. 思路  :先算了第3个第4个,算的时候发现只要在已经枚举出来的前边的状态中往后添加字母就行了,如果两个的都已经表示出来了,那第三个就可以在每个第二个后边加一个,在 ...