题意:三个人,在给定正方形内,求第一个人拿到珠宝的概率。珠宝随机出现在正方形内。

思路:中垂线+半平面相交。

  1 #include<cstdio>
  2 #include<cstring>
  3 #include<algorithm>
  4 #include<iostream>
  5 #include<cstdlib>
  6 #include<string>
  7 #include<cmath>
  8 #include<vector>
  9 using namespace std;
 10 const int maxn=1e5+7;
 11 const double eps=1e-8;
 12 const double pi=acos(-1);
 13
 14 double dcmp(double x)
 15 {
 16     if(fabs(x) < eps) return 0;
 17     else return x < 0 ? -1 : 1;
 18 }
 19
 20 struct Point
 21 {
 22     double x, y;
 23     Point(double x=0, double y=0):x(x),y(y) { }
 24 };
 25
 26 typedef Point Vector;
 27
 28 Vector operator + (const Point& A, const Point& B)
 29 {
 30     return Vector(A.x+B.x, A.y+B.y);
 31 }
 32
 33 Vector operator - (const Point& A, const Point& B)
 34 {
 35     return Vector(A.x-B.x, A.y-B.y);
 36 }
 37
 38 Vector operator * (const Point& A, double v)
 39 {
 40     return Vector(A.x*v, A.y*v);
 41 }
 42
 43 Vector operator / (const Point& A, double v)
 44 {
 45     return Vector(A.x/v, A.y/v);
 46 }
 47
 48 double Cross(const Vector& A, const Vector& B)
 49 {
 50     return A.x*B.y - A.y*B.x;
 51 }
 52
 53 double Dot(const Vector& A, const Vector& B)
 54 {
 55     return A.x*B.x + A.y*B.y;
 56 }
 57
 58 double Length(const Vector& A)
 59 {
 60     return sqrt(Dot(A,A));
 61 }
 62
 63 Vector Rotate(Vector A,double rad)
 64 {
 65     return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
 66 }
 67
 68 bool operator < (const Point& p1, const Point& p2)
 69 {
 70     return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
 71 }
 72
 73 bool operator == (const Point& p1, const Point& p2)
 74 {
 75     return p1.x == p2.x && p1.y == p2.y;
 76 }
 77
 78 Vector Normal(Vector A)
 79 {
 80     double L=Length(A);
 81     return Vector(-A.y/L,A.x/L);
 82 }
 83 struct Line
 84 {
 85     Point P;
 86     Vector v;
 87     double ang;
 88     Line() {}
 89     Line(Point P, Vector v):P(P),v(v)
 90     {
 91         ang = atan2(v.y, v.x);
 92     }
 93     bool operator < (const Line& L) const
 94     {
 95         return ang < L.ang;
 96     }
 97 };
 98
 99 bool OnLeft(const Line& L, const Point& p)
100 {
101     return Cross(L.v, p-L.P) > 0;
102 }
103
104
105 Point GetLineIntersection(const Line& a, const Line& b)
106 {
107     Vector u = a.P-b.P;
108     double t = Cross(b.v, u) / Cross(a.v, b.v);
109     return a.P+a.v*t;
110 }
111
112 const double INF = 1e8;
113
114 Point ansPoly[maxn];
115 int HalfplaneIntersection(vector<Line> L)     //L为切割平面的直线集合,求半平面交,返回点的个数,点存在anspoly数组中
116 {
117     int n = L.size();
118     sort(L.begin(), L.end()); // 按极角排序
119     int first, last;         // 双端队列的第一个元素和最后一个元素的下标
120     vector<Point> p(n);      // p[i]为q[i]和q[i+1]的交点
121     vector<Line> q(n);       //
122     q[first=last=0] = L[0];  //
123     for(int i = 1; i < n; i++)
124     {
125         while(first < last && !OnLeft(L[i], p[last-1])) last--;
126         while(first < last && !OnLeft(L[i], p[first])) first++;
127         q[++last] = L[i];
128         if(fabs(Cross(q[last].v, q[last-1].v)) < eps)   //
129         {
130             last--;
131             if(OnLeft(q[last], L[i].P)) q[last] = L[i];
132         }
133         if(first < last) p[last-1] = GetLineIntersection(q[last-1], q[last]);
134     }
135     while(first < last && !OnLeft(q[first], p[last-1])) last--; //
136     if(last - first <= 1) return 0; //
137     p[last] = GetLineIntersection(q[last], q[first]); //
138     // 从deque复制到输出中
139     int index=0;
140     for(int i = first; i <= last; i++) ansPoly[index++]=p[i];
141     return index;
142 }
143
144 double PolygonArea(int n,Point *p)
145 {
146     double area=0;
147     for(int i=1; i<n-1; i++)
148         area+=Cross(p[i]-p[0],p[i+1]-p[0]);
149     return area/2;
150 }
151
152 Point p[5];
153 int main()
154 {
155 //  freopen("in.txt","r",stdin);
156     while(cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y>>p[2].x>>p[2].y)
157     {
158         if(p[0].x==p[1].x&&p[0].y==p[1].y&&p[0].x==0)break;
159 //        Point zd1,zd2;
160         vector<Line>  vec;
161         vec.push_back(Line(Point(0,0),Point(1,0)));
162         vec.push_back(Line(Point(10000,0),Point(0,1)));
163         vec.push_back(Line(Point(10000,10000),Point(-1,0)));
164         vec.push_back(Line(Point(0,10000),Point(0,-1)));
165         Vector v=(p[1]-p[0]);
166         vec.push_back(Line((p[1]+p[0])*0.5,Normal(v)));
167         v=(p[2]-p[0]);
168         vec.push_back(Line((p[2]+p[0])*0.5,Normal(v)));
169         int m=HalfplaneIntersection(vec);
170         double ans=PolygonArea(m,ansPoly);
171         printf("%.3f\n",ans/(1.0*10000*10000));
172     }
173     return 0;
174 }

View Code

转载于:https://www.cnblogs.com/ITUPC/p/5137532.html

zoj 1670 Jewels from Heaven相关推荐

  1. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  2. zoj 1204 Additive equations

    ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...

  3. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  4. LeetCode 771. Jewels and Stones--Java和Python解法--简单

    题目地址:Jewels and Stones - LeetCode You're given strings J representing the types of stones that are j ...

  5. 模拟 ZOJ 3878 Convert QWERTY to Dvorak

    题目传送门 1 /* 2 模拟:手敲map一一映射,累! 3 除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:) 4 */ 5 #include <cstdio> 6 ...

  6. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 1 /* 2 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 3 矩阵连乘积问题,DP解决:状态转移方程: 4 dp[i][j] = min (dp[i][k] + dp[k+1] ...

  7. ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)

    ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...

  8. 九度OJ—题目1032:ZOJ

    题目描写叙述: 读入一个字符串.字符串中包括ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出.当某个字符用完时,剩下的仍然依照ZOJ的顺序输出. 输入: 题目包括多组用例,每组用例占一行,包括ZOJ ...

  9. ZOJ 1410 题解

    题目链接:http://acm.zju.edu.cn/show_problem.php?pid=1410 又是一道简单题,以前做过一次,结果放弃了,今天看了一下,觉得还是比较简单于是下手了. 题目的大 ...

最新文章

  1. Flex 布局详解 - 转自阮一峰老师
  2. 神经网络中参数数量的计算
  3. 已解决:Job for docker.service failed because the control process exited with error code. See “systemctl
  4. 压缩感知(III) A Compressed Sense of Compressive Sensing (III)
  5. 小波分析实验: 实验1 连续小波变换
  6. nmf算法 python_NMF算法简介及python实现
  7. 分享一套非常不错的bootstarp3.0.2响应式模板
  8. 流感传染(信息学奥赛一本通-T1191)
  9. sql server使用维护计划定时备份完整数据库、差异数据库
  10. B/S系统间跨域单点登录设计思路
  11. 配电室智能辅助控制系统
  12. Adobe CS2提供免费序列号
  13. Exchange高危0day漏洞 -- 直接拿下你的域控和服务器 -- 立即行动!CVE-2021-26855
  14. 10个JS精简代码无形装逼集合,最为致命,记得收藏好
  15. 已知有十六支男子足球队参加2008 北京奥运会。写一个程序,把这16 支球队随机分为4 个组。 注:参赛球队列表见附录 注2:使用Math.random 来产生随机数。(也可以使用其它方法) 2. 2
  16. 校园网络项目设计方案
  17. Android实现利用手势完成屏幕密码锁功能
  18. eDisMax查询解析器
  19. android实现忘记密码功能,Android忘记密码功能
  20. 制作多系统U盘(win10+ubuntu18+ 。。。)

热门文章

  1. case....when ...多重判断
  2. 孤荷凌寒自学python第三十八天初识python的线程控制
  3. Python的可视化包 – Matplotlib 2D图表(点图和线图,.柱状或饼状类型的图),3D图表(曲面图,散点图和柱状图)...
  4. stl set求交集 并集 差集
  5. strip lstrip rstrip
  6. css学习笔记3--灵活的背景定位
  7. OkHttpClient源码分析(五)—— ConnectInterceptor和CallServerInterceptor
  8. CSS导航条菜单:带小三角形
  9. java对象关系映射ROM
  10. 离线在CentOS上安装CDH