hdu 3340 Rain in ACStar 线段树区间等差数列更新
Rain in ACStar
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/problem/show/1385
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:
R P
(This type of instructions tell you sufficient information about the raindrops.)Q A B
(Ask you to report the volume of rain absorbed by soil of [A,B].)
Instructions are given in chronological order.
Input
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.
1000000000.
Output
It is guaranteed that the result is less than 1e8.
Sample Input
Sample Output
0.250
1.000
1.000
100.250
HINT
题意
下凸包雨,每次会下3-6个点组成的凸包雨
题解:
直接把凸包变成矩形面积求和就好了,我们对于大于上一个点的x轴的点记为正面积,对于小于的记为负面积
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//************************************************************************************** struct node
{
int x[],y[],z,n;
};
node op[maxn];
vector<int> po;
char str[];
int t,n,k;
map<int,int> H;
struct tree
{
int l,r,len;
double add1,add2,step,sum;
void init() { add1=add2=step=sum=; }
void fun(double a,double b,double c)
{
add1+=a; add2+=b; step+=c;
sum+=(a+b)*len/;
}
};
tree tree[maxn*]; double calu(int st,int ed,double add1,double step)
{
int len=po[ed]-po[st];
return add1+len*step;
}
void PushUp(int ind)
{
tree[ind].sum=tree[ind<<].sum+tree[ind<<|].sum;
}
void PushDown(int ind)
{
double add1=tree[ind].add1,add2=tree[ind].add2,step=tree[ind].step;
double tmp=calu(tree[ind].l,(tree[ind].l+tree[ind].r)/,add1,step);
tree[ind<<].fun(add1,tmp,step);
tree[ind<<|].fun(tmp,add2,step);
tree[ind].add1=tree[ind].add2=tree[ind].step=;
}
void build(int lft,int rht,int ind)
{
tree[ind].l=lft; tree[ind].r=rht;
tree[ind].init(); tree[ind].len=po[rht]-po[lft];
if(lft+!=rht)
{
int mid=tree[ind].l+tree[ind].r>>;
build(lft,mid,ind<<);
build(mid,rht,ind<<|);
}
}
void updata(int st,int ed,int ind,double add1,double add2,double step)
{
int lft=tree[ind].l,rht=tree[ind].r;
if(st<=lft&&rht<=ed) tree[ind].fun(add1,add2,step);
else
{
PushDown(ind);
int mid=tree[ind].l+tree[ind].r>>;
if(ed<=mid) updata(st,ed,ind<<,add1,add2,step);
else if(st>=mid) updata(st,ed,ind<<|,add1,add2,step);
else
{
double tmp=calu(st,mid,add1,step);
updata(st,mid,ind<<,add1,tmp,step);
updata(mid,ed,ind<<|,tmp,add2,step);
}
PushUp(ind);
}
}
double query(int st,int ed,int ind)
{
int lft=tree[ind].l,rht=tree[ind].r;
if(st<=lft&&rht<=ed) return tree[ind].sum;
else
{
PushDown(ind);
int mid=tree[ind].l+tree[ind].r>>;
double sum=;
if(st<mid) sum+=query(st,ed,ind<<);
if(ed>mid) sum+=query(st,ed,ind<<|);
PushUp(ind);
return sum;
}
}
void init()
{
memset(tree,,sizeof(tree));
po.clear();
memset(op,,sizeof(op));
H.clear();
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%s",str);
if(str[]=='R')
{
op[i].z=;
scanf("%d",&op[i].n);
for(int j=;j<op[i].n;j++)
{
scanf("%d%d",&op[i].x[j],&op[i].y[j]);
po.push_back(op[i].x[j]);
}
}
else
{
op[i].z=;
scanf("%d%d",&op[i].x[],&op[i].y[]);
po.push_back(op[i].x[]);
po.push_back(op[i].y[]);
}
}
sort(po.begin(),po.end());
po.erase(unique(po.begin(),po.end()),po.end());
for(int i=;i<po.size();i++)
H[po[i]]=i;
}
void solve()
{
for(int i=;i<n;i++)
{
int x1,y1,x2,y2;
if(op[i].z==)
{
for(int j=;j<op[i].n;j++)
{
x1=op[i].x[j];
y1=op[i].y[j];
x2=op[i].x[(j+)%op[i].n];
y2=op[i].y[(j+)%op[i].n];
if(x1>x2)
swap(x1,x2),swap(y1,y2);
else
y1=-y1,y2=-y2;
double step=(y1*1.0-y2*1.0)/(x1*1.0-x2*1.0);
updata(H[x1],H[x2],,y1,y2,step);
}
}
else
{
x1=op[i].x[],y1=op[i].y[];
printf("%.3lf\n",query(H[x1],H[y1],));
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
init();
build(,po.size()-,);
solve();
}
}
hdu 3340 Rain in ACStar 线段树区间等差数列更新的更多相关文章
- HDU 3340 Rain in ACStar(线段树+几何)
HDU 3340 Rain in ACStar pid=3340" target="_blank" style="">题目链接 题意:给定几个多 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU.1689 Just a Hook (线段树 区间替换 区间总和)
HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
- HDU 1698 Just a Hook(线段树区间更新查询)
描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
随机推荐
- linux系统分区参考
UPDATE: update is used to download package information from all configured sources. UPGRADE: upgrad ...
- Django项目上传到AWS服务器上
EC2是亚马逊(Amazon.com)提供的弹性云计算服务:Apache是一个跨平台的Web服务器端软件,可以使Python.PHP.Perl等语言编写的程序运行在服务器上:Django是一个Web程 ...
- Nginx服务安全设置和参数调优
1.添加参数隐藏Nginx版本号 vim /application/nginx/conf/nginx.conf #http标签下添加 server_tokens off; #测试 [root@cobb ...
- [ python ] 练习作业 - 2
1.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者. lic = [0, 1, 2, 3, 4, 5] def func(l): return l[1::2 ...
- rcnn ->fast rcnn->faster rcnn物体检测论文
faster rcnn中的rpn网络: 特征可以看做一个尺度51*39的256通道图像,对于该图像的每一个位置,考虑9个可能的候选窗口:三种面积{1282,2562,5122}×三种比例{1:1,1: ...
- HTML+CSS图文排版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- Python抓取微博评论
本人是张杰的小迷妹,所以用杰哥的微博为例,之前一直看的是网页版,然后在知乎上看了一个抓取沈梦辰的微博评论的帖子,然后得到了这样的网址 然后就用m.weibo.cn进行网站的爬取,里面的微博和每一条微博 ...
- 两周撸一个掘金微信小程序
利益相关 无 声明 这并不是掘金官方小程序(貌似没有搜到掘金 APP 对应的官方小程序),完全为第三者开发者开发,仅用于学习交流,禁止用于其他用途.若要使用官方正版,可访问掘金 官方网站,或下载掘金官 ...
- DotNetOpenAuth实践系列
写在前面 本人在研究DotNetOpenAuth的过程中,遇到很多问题,很多坑,花费了很多时间才调通这玩意,现在毫无保留的分享出来,希望博友们可以轻松的上手DotNetOpenAuth,减少爬坑时间. ...
- [转]基于Protel DXP软件的PCB高级编辑技巧大全
来源:基于Protel DXP软件的PCB高级编辑技巧大全 一.放置坐标指示 放置坐标指示可以显示出PCB板上任何一点的坐标位置. 启用放置坐标的方法如下:从主菜单中执行命令 Place/Coordi ...