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. bash和sh区别

    在一般的linux系统当中(如redhat),使用sh调用执行脚本相当于打开了bash的POSIX标准模式(等效于bash的 --posix 参数),一般的,sh是bash的“子集”,不是子集的部分. ...

  2. MySQ安装

    1.去官网下载安装包 .http://www.mysql.com/downloads/ 2.安装过程中会出现下面的提示:记得保存你的MySQL的初始的默认密码.如果没有注意,那么恢复起来有点麻烦,后续 ...

  3. HDU 2579/BFS/ Dating with girls(2)

    题目链接 /* 题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间. 关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可. */ #includ ...

  4. mysql char varchar 区别

    数据库建表  字符串字段类型的选择 char与varchar的区别: char      长度固定,char(M)类型的数据列里,每个值都占用M个字节,如果某个长度小于M,MySQL就会在它的右边用空 ...

  5. 项目总结SpringMVC相关

    流程文字概述1.用户发送请求至前端控制器DispatcherServlet2.DispatcherServlet收到请求调用HandlerMapping处理器映射器.3.处理器映射器找到具体的处理器, ...

  6. 学习笔记——策略模式Strategy

    策略模式,与模板模式一样,都是为了将接口和算法实现解耦,但策略模式更主要是整体算法的替换,而模板模式主要是流程一致,部分算法的替换. 个人理解为,一般算法替换,使用策略模式,当算法流程一致,可以提取为 ...

  7. MySQL常用命令总结2

    USE db_name; //使用(打开)数据库 SELECT DATABASE(); //查看当前打开的数据库 CREATE TABLE tb_name( column_name data_type ...

  8. PHP中将ip地址转成十进制数的两种实用方法

    As we all know that long2ip works as ip1.ip2.ip3.ip4 (123.131.231.212) long ip => (ip1 * 256 * 25 ...

  9. win7 系统保留分区 BCDedit

    系统保留分区简介编辑 “系统保留”分区示意图 Windows Vista/7出于安全考虑,在新装Windows Vista/7系统过程中,如果利用光盘的分区工具给硬盘分区时,系统默认的将一部分(100 ...

  10. Android Camera Api的心得

    (一) 前言最近看Camera的api,觉得写的真的不错.现在翻译过来,给大家分享分享,译文可能不太好,大家将就着看哈. (二) 正文1. CameraCamera是Android framework ...