hdu3340 线段树+多边形
来源:互联网 发布:clover软件 编辑:程序博客网 时间:2024/05/17 00:16
Rain in ACStar
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 788 Accepted Submission(s): 218
Problem Description
Maybe you have heard of Super Cow AC who is the great general of ACM Empire. However, do you know where he is from?
This is one of the ten biggest secrets of this world! And it is time to expose the truth!
Yes, Super Cow AC is from ACStar which is ten million light-year away from our earth. No one, even AC himself, knows how AC came to our home. The only memory in his head is the strange rain in ACStar.
Because of the special gravity of ACStar, the raindrops in ACStar have many funny features. They have arbitrary sizes, color and tastes. The most interesting parts of the raindrops are their shapes. When AC was very young, he found that all the drops he saw in air were convex hull. Once the raindrops fell to the ground, they would be absorb by the soil.
This year is set to be AC-year. In recognition of Great General AC's contribution to our empire, the Emperor decided to build a huge AC park. Inside this park there is a laboratory to simulate the rain in ACStar. As a researcher of this lab, you are appointed to measure the volume of rain absorbed by soil. To simplify this problem, scientists put the rain into two-dimensional plane in which the ground is represented as a straight line and the raindrops are convex polygon. So the area of the graphics stands for the volume of raindrops.
You will receive two types of instructions:
1.R P (This type of instructions tell you sufficient information about the raindrops.)
2.Q A B (Ask you to report the volume of rain absorbed by soil of [A,B].)
Instructions are given in chronological order.
This is one of the ten biggest secrets of this world! And it is time to expose the truth!
Yes, Super Cow AC is from ACStar which is ten million light-year away from our earth. No one, even AC himself, knows how AC came to our home. The only memory in his head is the strange rain in ACStar.
Because of the special gravity of ACStar, the raindrops in ACStar have many funny features. They have arbitrary sizes, color and tastes. The most interesting parts of the raindrops are their shapes. When AC was very young, he found that all the drops he saw in air were convex hull. Once the raindrops fell to the ground, they would be absorb by the soil.
This year is set to be AC-year. In recognition of Great General AC's contribution to our empire, the Emperor decided to build a huge AC park. Inside this park there is a laboratory to simulate the rain in ACStar. As a researcher of this lab, you are appointed to measure the volume of rain absorbed by soil. To simplify this problem, scientists put the rain into two-dimensional plane in which the ground is represented as a straight line and the raindrops are convex polygon. So the area of the graphics stands for the volume of raindrops.
You will receive two types of instructions:
1.R P (This type of instructions tell you sufficient information about the raindrops.)
2.Q A B (Ask you to report the volume of rain absorbed by soil of [A,B].)
Instructions are given in chronological order.
Input
The first line of the inputs is T(no more than 10), which stands for the number of test cases you need to solve.
After T, the inputs will be each test case. The first line of each case will be N(no more than 25000), representing for the numbers of instructions. The following N lines will give instructions of the two types.
For each instruction of type 1, it will be followed by a line listing P (at least 3 and at most 5) points representing the convex polygon of the coming raindrop. The points are started by the leftmost point and are given in counterclockwise order. It's guaranteed that no points of the same raindrop are in the same vertical line.
All numbers are positive integer no more than 1000000000.
After T, the inputs will be each test case. The first line of each case will be N(no more than 25000), representing for the numbers of instructions. The following N lines will give instructions of the two types.
For each instruction of type 1, it will be followed by a line listing P (at least 3 and at most 5) points representing the convex polygon of the coming raindrop. The points are started by the leftmost point and are given in counterclockwise order. It's guaranteed that no points of the same raindrop are in the same vertical line.
All numbers are positive integer no more than 1000000000.
Output
For each instruction of type 2, output the corresponding result, which should be printed accurately rounded to three decimals.
It is guaranteed that the result is less than 1e8.
It is guaranteed that the result is less than 1e8.
Sample Input
17Q 1 100R 410 10 11 10 13 11 12 11Q 10 11Q 1 100R 3100 20 120 20 110 30Q 1 100Q 12 120
Sample Output
0.0000.2501.0001.000100.250
/*hdu3340 线段树+多边形R x:表示在这有个x边形Q l r:查询在[l,r]之间的多边形的面积所以考虑用线段树解决,那么我们就要知道如何处理区间的面积,对于一个多边形,它的每一条边都可以在两端作垂直于x轴的垂线然后形成一个梯形,于是用图形上半部分的边形成的梯形和- 半部分的边形成的梯形和便能得到多边形面积。而且两个同高的梯形的面积和等同于上底和下底的叠加hhh-2016-03-02 20:54:04Accepted*/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <queue>#include <vector>using namespace std;typedef long long ll;typedef long double ld;const int maxn = 500200;map<int,int>has;vector<int> tp;char op[10];struct node{ int l,r; int mid() { return l+(r-l)/2; } double h1,h2,k,len; double area;} tree[maxn];void push_up(int r){ tree[r].area = tree[r<<1].area+tree[r<<1|1].area;}void build(int i,int l,int r){ tree[i].l = l,tree[i].r = r; tree[i].h1 = tree[i].h2 = tree[i].k = tree[i].area = 0; tree[i].len = tp[r]-tp[l]; if(l == r) return; if(l+1 != r) { build(i<<1,l,tree[i].mid()); build(i<<1|1,tree[i].mid(),r); push_up(i); }}void push_down(int i){ int lson = i<<1,rson =i<<1|1; double h1=tree[i].h1,h2=tree[i].h2,k=tree[i].k; double md = (tp[tree[i].mid()]-tp[tree[i].l])*k+h1; tree[lson].h1+=h1,tree[lson].h2+=md,tree[lson].k+=k; tree[lson].area += (h1+md)*tree[lson].len/2; tree[rson].h1+=md,tree[rson].h2+=h2,tree[rson].k+=k; tree[rson].area += (md+h2)*tree[rson].len/2; tree[i].h1 = tree[i].h2 = tree[i].k = 0;}void update(int i,int l,int r,double h1,double h2,double k){ if(tree[i].l >= l && tree[i].r <= r) { tree[i].h1+=h1,tree[i].h2+=h2,tree[i].k+=k; tree[i].area += (h1+h2)*tree[i].len/2; return ; } push_down(i); double md= (tp[tree[i].mid()]-tp[l])*k+h1; if(r <= tree[i].mid()) update(i<<1,l,r,h1,h2,k); else if(l >= tree[i].mid()) update(i<<1|1,l,r,h1,h2,k); else { update(i<<1,l,tree[i].mid(),h1,md,k); update(i<<1|1,tree[i].mid(),r,md,h2,k); } push_up(i);}double query(int i,int l,int r){ if(tree[i].l >= l && tree[i].r <= r) { return tree[i].area; } push_down(i); double ans = 0; if(l < tree[i].mid()) ans += query(i<<1,l,r); if(tree[i].mid() < r) ans += query(i<<1|1,l,r); push_up(i); return ans;}struct point{ int x[6],y[6]; int num; void get() { num = 0; scanf("%s",op); if(op[0] == 'R') { scanf("%d",&num); for(int i = 0; i < num; i++) { scanf("%d%d",&x[i],&y[i]); tp.push_back(x[i]); } } else { scanf("%d%d",&x[1],&y[1]); tp.push_back(x[1]); tp.push_back(y[1]); } }} Point[50010];int main(){ int T; scanf("%d",&T); while(T--) { int n; tp.clear(),has.clear(); scanf("%d",&n); for(int i =1;i <= n;i++) { Point[i].get(); } sort(tp.begin(),tp.end()); tp.erase(unique(tp.begin(),tp.end()),tp.end()); for(int i = 0;i < (int)tp.size();i++) has[tp[i]] = i; build(1,0,tp.size()-1); for(int i =1;i <= n;i++) { if(Point[i].num) { for(int j = 0;j < Point[i].num;j++) { int num = Point[i].num; int x1=Point[i].x[j],y1=Point[i].y[j]; int x2=Point[i].x[(j+1)%num],y2=Point[i].y[(j+1)%num]; if(x1 > x2)swap(x1,x2),swap(y1,y2); else y1=-y1,y2=-y2; double k = (1.0*y1-1.0*y2)/(1.0*x1-1.0*x2); update(1,has[x1],has[x2],y1,y2,k); // printf("%.3f\n",query(1,has[1],has[100])); } } else { int x = Point[i].x[1]; int y = Point[i].y[1]; printf("%.3f\n",query(1,has[x],has[y])); } } } return 0;}
0 0
- hdu3340 线段树+多边形
- hdu3340 线段树之多边形分解
- hdu3340(线段树+几何)
- ZOJ 3511 不相交切切多边形 线段树求最大边数
- 考试B 冰雪奇缘改版 多边形剖梯形+线段树维护区间
- HDU1154求线段在多边形内长度
- 高德地图绘制多边形和线段
- 点定位(线段,三角形,多边形)
- QT绘制多边形、渐变线段、文字、带线段的箭头
- 判断任意多边形与矩形的相交(线段与矩形相交或线段与线段相交)
- 判断任意多边形与矩形的相交(线段与矩形相交或线段与线段相交)
- 向量叉积的应用(三角形面积,线段相交,多边形面积,多边形凹凸性)
- ZOJ 1010 Area (判线段相交,简单多边形的面积)
- POJ 1410 判断线段相交点在多边形内外
- (beginer)线段求交:多边形面积 UVA 1301 - Fishnet
- 判断点及线段是否在多边形内
- ZOJ 1010 Area(判定线段是否构成多边形)
- vtk实战(五十)—计算线段与多边形的交点
- Gson
- Mathematics in ACM
- C#旅途 ----趁热打铁 活学活用 数组快排,查找,拷贝;
- debian中文输入法——拼音和五笔的解决方法
- 函数getopt(),及其参数optind
- hdu3340 线段树+多边形
- C++ STL map I don't want it to sort!
- 文本域组件JTextArea
- scikit入门学习笔记
- POJ 3686_The Windy's
- 每天一个linux命令(60):scp命令 【转】
- 计算机网络
- Qt tcp通信简单实现
- MXNet设计笔记之:深度学习的编程模式比较