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. TForm类有关属性简介

    http://www.cnblogs.com/pchmonster/archive/2012/01/02/2310377.html

  2. 前端知识复习二(js)

    JS的作用 页面特效 移动端 异步交互(AJAX) 服务器端开发(node.js) 由ECMAScript和dom(操作网页上的api).bom组成(操作浏览器的部分api) 输出到页面内容 cons ...

  3. Light OJ 1008

    找规律. 首先令n=sqrt(s),上取整.讨论当n为偶数时,若n*n-s<n则x=n,y=n*n-s+1否则x=-n*n+2*n+s-1,y=n;如果n为奇数,交换x,y即可,对称的. Sam ...

  4. Oracle 使用sql创建表空间及用户

    create tablespace OrcalDBNamedb datafile 'C:\OracleDBDirc\OrcalDBNamedb.dbf' size 300m; 创建用户create u ...

  5. 手机号码抽奖系统(JS)

    <html><head><title>手机号码抽奖</title><meta http-equiv="Content-Type" ...

  6. kafka configuration

    http://kafka.apache.org/08/configuration.html

  7. 款待奶牛(treat)

    款待奶牛(treat) 题目描述 FJ有n(1≤n≤2000)个美味的食物,他想卖掉它们来赚钱给奶牛.这些食物放在一些箱子里,它们有些有趣的特性:(1)这些食物被编号为1-n,每一天FJ可以从这排箱子 ...

  8. CentOS 在同一窗口打开文件夹

    1.打开一个文件夹 2.编辑 - 首选项 - 行为,勾选“总是在浏览器窗口打开”,点击关闭.

  9. 【Android Demo】通过WebService获取今日天气情况--转

    因为本身是在搞.NET方面的东东,现在在学习Android,所以想实现Android通过WebService接口来获取数据,网上很多例子还有有问题的.参考:Android 通过WebService进行 ...

  10. 【2013 ICCV】Abnormal Event Detection at 150 FPS in MATLAB

    2. method 把每一帧变成不同尺度,并且把每一层分成互不覆盖的patch.连续的5帧堆叠在一起形成时空立方体.对时空立方体计算3D梯度特征[11].这些视屏序列中的特征,根据空间位置的相关性,进 ...