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

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

 #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. Oracle索引扫描

    Oracle索引扫描:先通过index查找到索引的值,并根据索引的值对应的rowid值(对于非唯一索引可能返回多个rowid值)直接从表中得到具体的数据.一个rowid唯一的表示一行数据,该行对应的数 ...

  2. 【IT历史】SP和CP

    1.什么是SP?SP是英文Service Provider的缩写,中文翻译为服务提供商,通常是指在移动网内运营增值业务的社会合作单位.它们建立与移动网络建立相连的服务平台,为手机用户提供一系列信息服务 ...

  3. android报表图形引擎(AChartEngine)demo解析与源码

    AchartEngine支持多种图表样式,本文介绍两种:线状表和柱状表. AchartEngine有两种启动的方式:一种是通过ChartFactory.get***View()方式来直接获取到view ...

  4. Static File Middleware

    [ASP.NET Core] Static File Middleware   前言 本篇文章介绍ASP.NET Core里,用来处理静态档案的Middleware,为自己留个纪录也希望能帮助到有需要 ...

  5. TOKEN+签名验证

    TOKEN+签名验证 首先问大家一个问题,你在写开放的API接口时是如何保证数据的安全性的?先来看看有哪些安全性问题在开放的api接口中,我们通过http Post或者Get方式请求服务器的时候,会面 ...

  6. windows store app promise

    Promise.any ---- 参数是一个promise的数组.any的作用就是 promise 数组中任意一个 promise 执行完毕,就会执行 done内的函数 (function () { ...

  7. 388A Fox and Box Accumulation

    一开始贪心策略想错了! #include<cstdio> #include<algorithm> using namespace std; ]; int main() { in ...

  8. UPUPW PHP环境集成包

    UPUPW PHP环境集成包 http://www.upupw.net/

  9. Java集合类之Hashtable

    package com.test; import java.util.*; public class Demo7_3 { public static void main(String[] args) ...

  10. Android Binder设计与实现 - 设计篇

    要 Binder是Android系统进程间通信(IPC)方式之一.Linux已经拥有管道,system V IPC,socket等IPC手段,却还要倚赖Binder来实现进程间通信,说明Binder具 ...