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. VideoView的视频的全屏播放

    import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.I ...

  2. 《割绳子》《蜡笔物理学》《Contre Jour》《顽皮鳄鱼爱洗澡》等游戏用Box2D引擎实现物理部分的方法(转)

    从最热门游戏排行榜和flash游戏网站上,你能看到什么?许多2D游戏都有非常出色的物理学和美术设计.现在我们要学习那些游戏使用了什么物理学以及如何用Box2D制作它们. 除了知道是“什么”,更重要的是 ...

  3. Lucene中的 Query对象

    "Lucene中的 Query对象": 检 索前,需要对检索字符串进行分析,这是由queryparser来完成的.为了保证查询的正确性,最好用创建索引文件时同样的分析器. quer ...

  4. java类对象

    不错的文章 原文地址:(转载)java中的Class类与Class对象作者:albert1017 本文用作笔记之用,引用的网上资料: http://www.blogjava.net/formatmys ...

  5. asp 自我定时删除

    <% if now()>"2008-9-15" thenset myfso=server.CreateObject("scripting.filesystem ...

  6. ListView使用的时候遇到的一些问题

    昨天在做项目时,请求服务器的好友动态后,将好友动态和评论显示到界面上,用ListView显示,发现一进这个界面时,listView的适配器的getVIew()方法就会执行6次,后来发现原来是ListV ...

  7. (一)、Struts第一天

    (一).Struts第一天 1. JavaWeb知识回顾 n 客户端编程 HTLM/CSS/JS n XML技术 会写XML * 基本语法 * DTD * Schema 会读XML * Dom4J读取 ...

  8. 一个opencv 博客 大量文章(老版本编写C )

    http://blog.csdn.net/Augusdi/article/category/747412

  9. jq的事件对象的属性

    1.event.type() 该方法的作用是可以获取到时间的类型 $('a').click(function(){ alert(event.type);//获取事件类型 return  false;/ ...

  10. Servlet程序开发-- Servlet生命周期

    生命周期是一个程序的存在周期,受容器管理,所以容器决定生命周期. 生命周期包括 加载,初始化,服务,销毁,卸载 5个部分 加载:第一次使用的时候加载 初始化:init方法, 失败的话,直接卸载,如果成 ...