Description

  ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of various lengths, connected by flexible joints. The end of the i-th segment is joined to the beginning of the i + 1-th one, for 1 ≤ i < n. The beginning of the first segment is fixed at point with coordinates (0, 0) and its end at point with coordinates (0, w), where w is the length of the first segment. All of the segments lie always in one plane, and the joints allow arbitrary rotation in that plane. After series of unpleasant accidents, it was decided that software that controls the crane must contain a piece of code that constantly checks the position of the end of crane, and stops the crane if a collision should happen.

  Your task is to write a part of this software that determines the position of the end of the n-th segment after each command. The state of the crane is determined by the angles between consecutive segments. Initially, all of the angles are straight, i.e., 180o. The operator issues commands that change the angle in exactly one joint. 

 
  题意就是一个挖掘机,饿。。。吊车,的机械臂,有n节,可以转动,问每次转动之后最后一个位置。
  刚开始的时候想到是用数组表示每一个点,然后用线段树更新某一个区间,但是超时了,因为每次更新都要让上一次更新全部更新彻底,其实就是直接全部更新,反而还不如直接模拟。后来看了看题解,提到向量。。。就是用数组记录区间内所有向量的和,那么所有区间的和就是答案,而且,每次旋转d度的话对这个区间也是旋转d度,没有区别。。。
  另外被这个题坑了两个小时,还是今年的头两个小时。。。建树的时候没有更新彻底,看来以后自己测试一定要多组数据。。。。
 
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath> #define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; struct state
{
double x,y;
}; const double PI=atan2(1.0,1.0)*; state BIT[*];
int COL[*];
int rang[]; void change(int po,int ct)
{
double tang;
double len; tang=atan2(BIT[po].y,BIT[po].x);
len=sqrt(BIT[po].x*BIT[po].x+BIT[po].y*BIT[po].y);
tang+=ct*PI/180.0;
BIT[po].x=len*cos(tang);
BIT[po].y=len*sin(tang);
} void pushUP(int po)
{
BIT[po].x=BIT[po*].x+BIT[po*+].x;
BIT[po].y=BIT[po*].y+BIT[po*+].y;
} void pushDown(int po)
{
if(COL[po])
{
change(po*,COL[po]);
change(po*+,COL[po]); COL[po*]+=COL[po];
COL[po*+]+=COL[po]; COL[po]=;
}
} void build_tree(int L,int R,int po)
{
COL[po]=; //DON'T FORGET !!! if(L==R)
{
int temp; BIT[po].x=;
COL[po]=;
scanf("%d",&temp);
BIT[po].y=temp; return;
} int M=(L+R)/; build_tree(lson);
build_tree(rson); pushUP(po);
} void update(int ul,int ur,int ut,int L,int R,int po)
{
if(ul<=L&&ur>=R)
{
change(po,ut);
COL[po]+=ut;
COL[po]%=;
return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
update(ul,ur,ut,lson);
if(ur>M)
update(ul,ur,ut,rson); pushUP(po);
} int main()
{
int n,c;
int a,b;
int cas=; while(~scanf("%d %d",&n,&c))
{
if(cas++)
printf("\n"); build_tree(,n,); for(int i=;i<=n;++i)
rang[i]=; for(int i=;i<=c;++i)
{
scanf("%d %d",&a,&b);
b-=;
if(b==-)
b=;
update(a+,n,b-rang[a],,n,);
rang[a]=b; printf("%.2lf %.2lf\n",BIT[].x,BIT[].y);
}
} return ;
}

(中等) POJ 2991 Crane , 几何+线段树。的更多相关文章

  1. POJ 2991 Crane(线段树+计算几何)

    POJ 2991 Crane 题目链接 题意:给定一个垂直的挖掘机臂.有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标 思路:线段树.把每一段当成 ...

  2. POJ 2991–Crane【线段树+几何】

    题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...

  3. POJ 2991 Crane(线段树)

    Crane Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7687   Accepted: 2075   Special J ...

  4. POJ 2991 Crane (线段树)

    题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...

  5. POJ - 2991 Crane (段树+计算几何)

    Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...

  6. [poj 2991]Crane[线段树表示向量之和,而非数量]

    题意: 起重机的机械臂, 由n段组成, 对某一些连接点进行旋转, 询问每次操作后的末端坐标. 思路: 由于旋转会影响到该点之后所有线段的角度, 因此容易想到用线段树记录角度, 成段更新. (但是不是每 ...

  7. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

  8. poj 3277 City Horizon (线段树 扫描线 矩形面积并)

    题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ...

  9. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

随机推荐

  1. JPA 系列教程6-单向多对多

    JPA中的@ManyToMany @ManyToMany注释表示模型类是多对多关系的一端. @JoinTable 描述了多对多关系的数据表关系. name 属性指定中间表名称 joinColumns ...

  2. UITabBarItem's appearance

    1.我们知道,用tabBarController创建出来默认的tabBar似这个样子滴... -----------------我是图片分割线----------------------------- ...

  3. jQuery 图片随滚动条滚动加载

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. YII2 过滤器 filters

    使用过滤器 过滤器本质上是一类特殊的 行为,所以使用过滤器和 使用 行为一样. 可以在控制器类中覆盖它的 yii\base\Controller::behaviors() 方法来申明过滤器, 如下所示 ...

  5. Socket在手机上的应用

    usb读取:pid vid --可以唯一的确定设备获取手机驱动socket固定端口通信 wifipc机在局域网内,udp的数据包(整个网段) 蓝牙配对 bluetoothsocket 如果放大:可以分 ...

  6. FZU 2170 花生的序列(动态规划)

    动态规划,转移方程为 dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD,定义还是比较裸的,讨论一下就可以了 #include <iostream> #inclu ...

  7. Mac os 10.11 更新ruby

    1.装cocoapods,ruby版本忒低->开始更新ruby->开始更新gem,这是一条不归路啊同志们,各种permission denied,各种路径不存在,各种路径没有读写权限,各种 ...

  8. PAT (Advanced Level) 1066. Root of AVL Tree (25)

    AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<c ...

  9. iOS LaunchScreen和LaunchImage的转换启动图

    今天开始设置一个新项目的启动图,需要我自己设置,我在UI那拿到以前格式的启动图不知道为何需要那么多图,我记得用LaunchScreen只需一张即可,利用自动布局,今天看到这么多图,发现他用的是Laun ...

  10. linux下用script和scriptreplay对命令行操作录像

    以前查看自己的历史操作,都是history里来查看的,只有命令,有时候系统返回的什么也没有,看了script可以对自己的操作进行录像,于是自己也做个. 要记录操作之前输入命令: [root@wulao ...