POJ-2991 Crane(区间更新+向量旋转)
题目大意:n个向量首尾相连,每次操作使某个区间中的所有向量都旋转同样的角度。每次操作后都回答最后一个向量的坐标。
题目分析:区间维护向量信息。向量旋转:x1=x0*cos(t)-y0*sin(t),y1=x0*sin(t)+y0*cos(t),其中t为旋转的角度。
代码如下:
# include<iostream>
# include<cmath>
# include<algorithm>
# include<cstdio>
using namespace std;
# define mid (l+(r-l)/2) const int N=10005;
const double PI=acos(-1.0); double x[N<<2],y[N<<2];
int lazy[N<<2];
int angle[N]; inline void read(int &x)
{
x=0;
char c;
while((c=getchar())&&(c<'0'||c>'9'));
x=c-'0';
while(c=getchar()){
if(c<'0'||c>'9') break;
x=x*10+c-'0';
}
} inline double f(int x)
{
return x*PI/180.0;
} inline void pushUp(int rt)
{
x[rt]=x[rt<<1]+x[rt<<1|1];
y[rt]=y[rt<<1]+y[rt<<1|1];
} inline void pushDown(int rt)
{
if(lazy[rt]==0) return ;
lazy[rt<<1]+=lazy[rt];
lazy[rt<<1|1]+=lazy[rt]; double xx=x[rt<<1];
double yy=y[rt<<1];
x[rt<<1]=xx*cos(f(lazy[rt]))-yy*sin(f(lazy[rt]));
y[rt<<1]=xx*sin(f(lazy[rt]))+yy*cos(f(lazy[rt])); xx=x[rt<<1|1];
yy=y[rt<<1|1];
x[rt<<1|1]=xx*cos(f(lazy[rt]))-yy*sin(f(lazy[rt]));
y[rt<<1|1]=xx*sin(f(lazy[rt]))+yy*cos(f(lazy[rt]));
lazy[rt]=0;
} inline void build(int rt,int l,int r)
{
lazy[rt]=0;
if(l==r){
x[rt]=0.0;
int a;
read(a);
y[rt]=a;
}else{
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
pushUp(rt);
}
} inline void update(int rt,int l,int r,int L,int R,int a)
{
if(L<=l&&r<=R){
lazy[rt]+=a;
double xx=x[rt];
double yy=y[rt];
x[rt]=xx*cos(f(a))-yy*sin(f(a));
y[rt]=xx*sin(f(a))+yy*cos(f(a));
}else{
pushDown(rt);
if(L<=mid) update(rt<<1,l,mid,L,R,a);
if(R>mid) update(rt<<1|1,mid+1,r,L,R,a);
pushUp(rt);
}
} int main()
{
int n,m;
bool first=true;
while(~scanf("%d%d",&n,&m))
{
if(!first) puts("");
first=false;
build(1,0,n-1);
for(int i=0;i<n;++i)
angle[i]=180;
int a,b;
while(m--){
scanf("%d%d",&a,&b);
update(1,0,n-1,a,n-1,b-angle[a-1]);
angle[a-1]=b;
printf("%.2lf %.2lf\n",x[1],y[1]);
}
}
return 0;
}
POJ-2991 Crane(区间更新+向量旋转)的更多相关文章
- [poj 2991]Crane[线段树表示向量之和,而非数量]
题意: 起重机的机械臂, 由n段组成, 对某一些连接点进行旋转, 询问每次操作后的末端坐标. 思路: 由于旋转会影响到该点之后所有线段的角度, 因此容易想到用线段树记录角度, 成段更新. (但是不是每 ...
- POJ 2991 Crane(线段树+计算几何)
POJ 2991 Crane 题目链接 题意:给定一个垂直的挖掘机臂.有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标 思路:线段树.把每一段当成 ...
- (中等) POJ 2991 Crane , 几何+线段树。
Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...
- POJ 2991 Crane (线段树)
题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...
- POJ - 2991 Crane (段树+计算几何)
Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...
- POJ 2991–Crane【线段树+几何】
题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...
- POJ 2991 Crane
线段树+计算几何,区间更新,区间求和,向量旋转. /* *********************************************** Author :Zhou Zhentao Ema ...
- C - A Simple Problem with Integers - poj 3468(区间更新)
题意:有一个比较长的区间可能是100000.长度, 每个点都有一个值(值还比较大),现在有一些操作,C abc, 把区间a-b内全部加上c, Qab,求区间ab的值. 分析:很明显我们不可能对区间的每 ...
- POJ 2991 Crane(线段树)
Crane Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7687 Accepted: 2075 Special J ...
随机推荐
- 图像显示与加载——opencv(转)
cvLoadImage() 函数:IplImage* cvLoadImage("图像名称",参数): 函数作用:加载图片: 函数返回值:为IplImage结构体: 参数说明:参数值 ...
- Microsoft Visual Studio Ultimate 2013 with Update 3 CN+EN
官方90天试用版. Microsoft Visual Studio Ultimate 2013 with Update 3 - 简体中文DVD5 ISO image (SHA-1: 9A306631A ...
- 《day16_多线程细节_Eclipse使用》
多线程的一些细节: 1,面试题:sleep方法和wait方法异同点是什么? 相同点:可以让线程处于冻结状态. 不同点: 1, sleep必须指定时间. wait可以指定时间,也可以不指定时间. 2, ...
- web api post传一个参数时 值永远是null
这个问题纠结了我一个早上,不管用什么样的传参方法,走到控制器中,那个参数永远不变的等于null 在网上找了很多解决方案 上面这个是从网上截图的,第一:要将参数标记为[FromBody],变为简单参数 ...
- android-volley-at-a-glance
http://liubin.org/2013/05/27/android-volley-at-a-glance/ http://www.androidhive.info/2014/05/android ...
- Ch2.Making Reconmmendation in PCI
做<Programing Collective Intelligence>中chapter 2.Making Recommendation的实例,有3个问题花了好长时间: 1. 遇到报错& ...
- QT5.4关联VS2010,配置VAssistX关联Qt类
1.参考网站:http://www.kavenblog.com/?p=272 2.下载插件:http://www.qt.io/zh-hans/download-open-source/#section ...
- HDOJ-三部曲-1001-Flip Game
Flip Game Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Su ...
- Connection to DB
Connect to MySQL PHP5 and later can work with a MySQL database using MySQLi extension PDO PDO will w ...
- (并查集 or BFS+二分)HDU5652
点击打开链接 并查集: #include<cstdio> #define N 505 using namespace std; struct node { int x,y; }; char ...