hdu5448-Marisa’s Cake 构成的所有多边形面积的和
来源:互联网 发布:仁川登陆作战影评知乎 编辑:程序博客网 时间:2024/05/20 13:15
Marisa’s Cake
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 264 Accepted Submission(s): 152
Problem Description
Today is Marisa’s birthday and she is given a cake the shape of a convex polygon of n vertices. Furthermore, all the n vertices are all going to be on integer points of the Cartesian coordinate system. Marisa asks her friend Reimu to randomly cut off some vertices of the cake. The set of vertices chosen to be cut off has size at most n−3 , and all possible choices have the same probability to be picked up. In order to remove all chosen vertices, Reimu might cut the cake several times. Since Reimu is a perfectionist, she will always cut the cake from one vertex to another. Hence, Reimu’s cutting will not generate vertices which are not in the original polygon.
Marisa wants to know the expected size of the cake she might get, and because you are madly in love with her, you decided to do anything she wants for her! You take out your laptop and are ready to calculate the expected size for Marisa. However, Marisa is bad with fractions. She wants to make sure the answer she gets is always an integer. To do that, she would like you to multiply the answer with the total number of possible cakes there are. Unfortunately, that still doesn’t guarantee the answer be an integer. An additional 2 must also be multiplied into the answer as well. For example, letA=(0,0),B=(1,0),C=(1,1),D=(0,2) and ABCD is the shape of Marisa’s birthday cake. There are 5 possible pieces ABCD,ABC,BCD,CDA,DAB that Marisa might get, and the corresponding area of these convex polygons are 32,12,12,1,1 respectively. The expected size of the cake that Marisa might get is (32+12+12+1+1)÷5=910 , and what you should tell Marisa 910×5×2=9 . Calculate the answer for Marisa and who knows, maybe she would love you back!
Marisa wants to know the expected size of the cake she might get, and because you are madly in love with her, you decided to do anything she wants for her! You take out your laptop and are ready to calculate the expected size for Marisa. However, Marisa is bad with fractions. She wants to make sure the answer she gets is always an integer. To do that, she would like you to multiply the answer with the total number of possible cakes there are. Unfortunately, that still doesn’t guarantee the answer be an integer. An additional 2 must also be multiplied into the answer as well. For example, let
Input
The first line on the input contains an integer T(T≤10) . There will be T test cases. The first line of each test case contains an integer n(3≤n≤100000) indicating the number of vertices of the convex polygon. The i−th of the following n lines contains two integers xi and yi(0≤x,y≤109) separated by a blank. (xi,yi) is the i−th vertex of the convex polygon, and (x1,y1),...,(xn,yn) will be in counterclockwise order.
Output
For each test case, output a number as the answer. In case the answer is greater than 1000000006 , please modulo the answer with 1000000007 . (You might figure out by now that Marisa is not good at dealing with large numbers either)
Sample Input
240 01 01 10 251 13 13 22 31 2
950题目大意是给你一些点,这些点构成了一个凸多边形,然后求这些点中任意构成的多边形的面积和。由于题目里要求得到的是面积的两倍,因为点都是整点,所以我们直接使用叉积就可以了答案如下:∑i=1n(2i−1fi)×h(i−1)+g(i−1)×(2n−i−1fi)代码如下:#include <cstdio>typedef long long LL;const int maxn = 100010, mod = 1000000007, inv2 = 500000004;int t, n, pw1[maxn], pw2[maxn], x, y, pre1x, pre1y, pre2x, pre2y, ans;int mod_add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}int mod_sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}int det(int x1, int y1, int x2, int y2){ return mod_sub((LL)x1 * y2 % mod, (LL)x2 * y1 % mod);}int main(){ scanf("%d", &t); pw1[0] = 1; for(int i = 1; i < maxn; ++i) pw1[i] = (LL)pw1[i - 1] * 2 % mod; // + pw2[0] = 1; for(int i = 1; i < maxn; ++i) pw2[i] = (LL)pw2[i - 1] * inv2 % mod; // - while(t--) { scanf("%d", &n); pre1x = pre1y = pre2x = pre2y = ans = 0; for(int i = 1; i <= n; ++i) { scanf("%d%d", &x, &y); ans = mod_add(ans, (LL)pw1[i - 1] * det(x, y, pre2x, pre2y) % mod); ans = mod_add(ans, (LL)(i == n ? inv2 : pw1[n - i - 1]) * det(pre1x, pre1y, x, y) % mod); pre1x = mod_add(pre1x, (LL)x * pw1[i] % mod); // + pre1y = mod_add(pre1y, (LL)y * pw1[i] % mod); // + pre2x = mod_add(pre2x, (LL)x * pw2[i] % mod); // - pre2y = mod_add(pre2y, (LL)y * pw2[i] % mod); // - } printf("%d\n", ans); } return 0;}
点击打开链接http://acm.hdu.edu.cn/showproblem.php?pid=5448
阅读全文
0 0
- hdu5448-Marisa’s Cake 构成的所有多边形面积的和
- HDU 5448 Marisa’s Cake(n个点中任意点组成的多边形面积之和)
- 2015 ACM/ICPC Asia Regional Changchun Online 1012 hdu5448 Marisa’s Cake
- HDOJ 5448 Marisa’s Cake
- HDU 5448 Marisa’s Cake
- 【HDU 5448】Marisa’s Cake
- 【多边形面积】求多边形的面积 pol
- 多边形和圆的面积并
- 求圆和多边形的面积交
- hdu 5130 圆和多边形的面积
- 多边形内角和与多边形的面积公式
- 算法:分治法求凸包上的点以及由凸包所构成的多边形的面积
- 计算多边形的面积
- 多边形的面积
- 计算多边形的面积
- 计算多边形的面积
- 计算多边形的面积
- 任意多边形的面积
- python并发处理concurrent.futures
- MySQL基础(1)——基本概念
- C代码编译成在android上的可执行程序
- write
- HDU 5448 Marisa’s Cake(n个点中任意点组成的多边形面积之和)
- hdu5448-Marisa’s Cake 构成的所有多边形面积的和
- 深度学习——激活函数
- JavaScript快速入门(一)
- RobotStudio结课作业——汽车覆盖件锻压/焊接/喷涂过程工作站
- 剑指offer第二题替换空格
- 学习资源
- Swift_Unicode
- 【太原·签约】中企动力助力山西省健康协会步入互联网+时代
- 【备忘】2017小凡老师泰牛Web基础班项目实战玩完整版-美团网项目