UESTC_Rain in ACStar 2015 UESTC Training for Data Structures

时间:2021-10-12 23:13:23

L - Rain in ACStar

Time Limit: 9000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

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.

UESTC_Rain in ACStar 2015 UESTC Training for Data Structures<Problem L>

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.

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 108.

Sample input and output

Sample Input Sample Output
1
7
Q 1 100
R 4
10 10 11 10 13 11 12 11
Q 10 11
Q 1 100
R 3
100 20 120 20 110 30
Q 1 100
Q 12 120
0.000
0.250
1.000
1.000
100.250

解题报告

思路很清晰,首先对x离散化,之后的操作就是给某段区间加上一段等差数列.

同时面积的更新当x1 < x2时添加负面积,x1 > x2添加正面积即可

使用线段树来维护,线段树存储四个值:

Double st //左边的增值

Double ed //右边的增值

Double k //单位距离的增值

Double sum //该区间内的S和

!注意下列几点

1.建树从[L,R]→[L,mid] + [mid,R],不要+个1.。不然中间那段等于是被黑了

2.Updata函数!!!!(本题最需注意的地方),一共三种情况:

1:更新区间[ql,qr]在当前区间[l,r]中mid的左边,此时传递不需要任何改变

2.更新区间[ql,qr]在当前区间[l,r]中mid的右边,此时传递不需要任何改变

3.更新区间[ql,qr]在当前区间[l,r]中mid的两侧,需要将中间的值计算出来然后再次传递下去,同时修改!!!两边的ql,qr值!!!!!!!!!!!!!!!!!!!!!!

注意了以上几点,那么本题也就迎刃而解了

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std;
const int maxn = + ;
int p[maxn*],hash__[maxn*]; typedef struct Query
{
int type,size;
int x[],y[],id[];
}; Query q[maxn]; typedef struct data
{
int l,r,len;
double st,ed,k,sum;
void add(double a,double b,double c)
{
st += a;
ed += b;
k += c;
sum += (a+b)*len*0.50;
}
}; data tree[maxn*]; inline double getnext(int x1,int x2,double st,double k)
{
return (double)(p[x2] - p[x1]) * k + st; // x2 > x1
} void push_up(int cur)
{
tree[cur].sum = tree[cur*].sum + tree[cur*+].sum;
} void push_down(int cur)
{
double st = tree[cur].st;
double ed = tree[cur].ed;
double k = tree[cur].k;
int l = tree[cur].l;
int r = tree[cur].r;
int mid = l + (r-l)/;
double midval = getnext(l,mid,st,k);
tree[cur*].add(st,midval,k);
tree[cur*+].add(midval,ed,k);
tree[cur].st = .;
tree[cur].ed = .;
tree[cur].k = .;
} void build_tree(int cur,int l,int r)
{
tree[cur].l = l , tree[cur].r = r , tree[cur].len = p[r]-p[l];
tree[cur].st = tree[cur].ed = tree[cur].k = tree[cur].sum = .;
if (r - l > )
{
int mid = l + (r-l) / ;
build_tree(*cur,l,mid);
build_tree(*cur+,mid,r);
}
} void updata(int ql,int qr,int cur,double st,double ed,double k )
{
int l = tree[cur].l , r = tree[cur].r;
if (l >= ql && r <= qr)
tree[cur].add(st,ed,k);
else
{
push_down(cur);
int mid = l + (r-l) / ;
/*
更新有三种情况
*/
if (qr <= mid)
{
updata(ql,qr,*cur,st,ed,k); //完全在左边
}
else if (ql >= mid)
{
updata(ql,qr,*cur+,st,ed,k); //完全在右边
}
else
{
double news = getnext(ql,mid,st,k); //夹在中间
updata(ql,qr,*cur,st,news,k);
updata(mid,qr,*cur+,news,ed,k);
}
push_up(cur);
}
} double query(int ql,int qr,int cur)
{
int l = tree[cur].l , r = tree[cur].r;
if (l >= ql && r <= qr)
return tree[cur].sum;
else
{
double res = .;
push_down(cur);
int mid = l + (r-l) / ;
if (mid > ql)
res += query(ql,qr,*cur);
if (mid < qr)
res += query(ql,qr,*cur+);
push_up(cur);
return res;
}
} inline double getk(int x1,int y1,int x2,int y2)
{
return (double)(y2-y1)/(double)(x2-x1);
} int main(int argc,char *argv[])
{
int Case;
scanf("%d",&Case);
while(Case--)
{
int n;
int psize = ;
scanf("%d",&n);
memset(p,,sizeof(p));
memset(hash__,,sizeof(hash__));
memset(q,,sizeof(q));
for(int i = ; i < n ; ++ i)
{
char oper[];
scanf("%s",oper);
if (oper[] == 'R')
{
q[i].type = ;
int size;
scanf("%d",&size);
q[i].size = size;
for(int j = ; j < size ; ++ j)
{
int x,y;
scanf("%d%d",&x,&y);
q[i].x[j] = x , q[i].y[j] = y , q[i].id[j] = psize;
p[psize++] = x;
}
}
else
{
q[i].type = ;
int x1,x2;
scanf("%d%d",&x1,&x2);
q[i].x[] = x1;
q[i].x[] = x2;
q[i].id[] = psize;
p[psize++] = x1;
q[i].id[] = psize;
p[psize++] = x2;
}
}
memcpy(hash__,p,sizeof(int)*psize);
sort(p,p+psize);
int c = unique(p,p+psize) - p;
for(int i = ; i < psize ; ++ i)
hash__[i] = lower_bound(p,p+c,hash__[i]) - p;
build_tree(,,c-); // Tree set
for(int i = ; i < n ; ++ i)
{
if (q[i].type & )
{
for(int j = ; j < q[i].size ; ++ j)
{
int c1 = j;
int c2 = (j+)%q[i].size;
int t1 = hash__[q[i].id[c1]];
int t2 = hash__[q[i].id[c2]];
int x1 = q[i].x[c1];
int y1 = q[i].y[c1];
int x2 = q[i].x[c2];
int y2 = q[i].y[c2];
if (x1 < x2)
{
y1 *= -;
y2 *= -;
double k = getk(x1,y1,x2,y2); //添加负面积
updata(t1,t2,,y1,y2,k);
}
else
{
double k = getk(x1,y1,x2,y2); //添加正面积
updata(t2,t1,,y2,y1,k);
}
}
}
else
{
int c1 = ;
int c2 = ;
int t1 = hash__[q[i].id[c1]];
int t2 = hash__[q[i].id[c2]];
printf("%.3lf\n",query(t1,t2,));
}
}
}
return ;
}

UESTC_Rain in ACStar 2015 UESTC Training for Data Structures<Problem L>的更多相关文章

  1. UESTC&lowbar;秋实大哥与战争 2015 UESTC Training for Data Structures&lt&semi;Problem D&gt&semi;

    D - 秋实大哥与战争 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  2. UESTC&lowbar;Sliding Window 2015 UESTC Training for Data Structures&lt&semi;Problem K&gt&semi;

    K - Sliding Window Time Limit: 18000/6000MS (Java/Others)     Memory Limit: 131072/131072KB (Java/Ot ...

  3. UESTC&lowbar;Islands 2015 UESTC Training for Data Structures&lt&semi;Problem J&gt&semi;

    J - Islands Time Limit: 30000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Su ...

  4. UESTC&lowbar;秋实大哥与快餐店 2015 UESTC Training for Data Structures&lt&semi;Problem C&gt&semi;

    C - 秋实大哥与快餐店 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  5. UESTC&lowbar;秋实大哥搞算数 2015 UESTC Training for Data Structures&lt&semi;Problem N&gt&semi;

    N - 秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  6. UESTC&lowbar;秋实大哥与线段树 2015 UESTC Training for Data Structures&lt&semi;Problem M&gt&semi;

    M - 秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  7. UESTC&lowbar;秋实大哥下棋 2015 UESTC Training for Data Structures&lt&semi;Problem I&gt&semi;

    I - 秋实大哥下棋 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  8. UESTC&lowbar;秋实大哥打游戏 2015 UESTC Training for Data Structures&lt&semi;Problem H&gt&semi;

    H - 秋实大哥打游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  9. UESTC&lowbar;秋实大哥去打工 2015 UESTC Training for Data Structures&lt&semi;Problem G&gt&semi;

    G - 秋实大哥去打工 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

随机推荐

  1. AngularJS 细节

    AngularJS 表达式({{ expression }})类似于 AngularJS ng-bind 例子: <span>表达式</span> <div ng-app ...

  2. mysql5&period;x&lpar;&lt&semi;7&rpar; sql文件导入到5&period;7

    一.修改sql—model http://www.linuxidc.com/Linux/2016-09/135372.htm

  3. 【UVA 11462】 Age Sort(基数排序)

    题 题意 给你最多2000000个数据,大小是1到99的数,让你排序输出. 分析 快排也可以过.不过这题本意是要基数排序(桶排序),就是读入年龄age, a[age]++,然后输出时,从1到99岁(看 ...

  4. 10&period;Android之ProgressDialog进度对话框学习

    APP应用中经常会下载某些东西,这里面有涉及到进度对话框,今天来学习下. 首先,布局里放进两个按钮,点击一个显示条形进度条,另一个显示圆形进度条.代码如下: <?xml version=&quo ...

  5. Oracle SQL篇(四)group by 分组与分组的加强 rollup

        分组操作group by 和分组的强化(rollup) 分组操作和分组函数的使用,对于编写SQL语句的人来说,是最基本的概念. 我们来看下面的例子: 在这里我们使用员工表EMP scott@D ...

  6. Listview的OnScrollListener的滑动监听实现分页加载

    //---------------主布局文件---------------------------- <ListView android:layout_width="fill_pare ...

  7. 你不知道的JSON&period;stringify和JSON&period;parse

    json是JavaScript 对象表示法(JavaScript Object Notation),是一种简单的数据格式,类似于XML,其格式为名称/值对,数据用逗号隔开,名称必须用双引号括起来.例如 ...

  8. js匿名函数,闭包

    http://www.cnblogs.com/chenxianbin89/archive/2010/01/28/1658392.html

  9. java线程interrupt、interrupted 、isInterrupted区别

    前言 在分析interrupt之前,应该先了解java里线程有5种状态,其中有一个阻塞状态,interrupt和阻塞有关. interrupt() 方法 作用于要中断的那个线程. interrupt( ...

  10. jdk各种包安装方式

    大家都知道,现在JAVA的发展可谓是如日中天,它覆盖面非常广泛,小到个人PC,大到商业应用都能见到它的身影.以前它是由SUN公司来维护的,现在已经归属到甲骨文旗下了. 今天我们来学习一下Java JD ...