POJ 2991 Crane(线段树+计算几何)
POJ 2991 Crane
题意:给定一个垂直的挖掘机臂。有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标
思路:线段树。把每一段当成一个向量,这样每一段的坐标就等于前几段的坐标和,然后每次旋转的时候,相当于把当前到最后位置所有加上一个角度,这样就须要区间改动了。然后每次还须要查询s,和s + 1当前的角度,所以须要单点查询,这样用线段树去维护就可以
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; const int N = 10005;
const double PI = acos(-1.0); #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) int n, m;
double COS[721], SIN[721]; struct Node {
int l, r, lazy, R;
double x, y;
void gao(int ang) {
R = (R + ang) % 360;
lazy = (lazy + ang) % 360;
double tmpx = x, tmpy = y;
x = COS[ang + 360] * tmpx - SIN[ang + 360] * tmpy;
y = SIN[ang + 360] * tmpx + COS[ang + 360] * tmpy;
}
} node[N * 4]; void pushup(int x) {
node[x].x = node[lson(x)].x + node[rson(x)].x;
node[x].y = node[lson(x)].y + node[rson(x)].y;
} void pushdown(int x) {
if (node[x].lazy) {
node[lson(x)].gao(node[x].lazy);
node[rson(x)].gao(node[x].lazy);
node[x].lazy = 0;
}
} void build(int l, int r, int x = 0) {
node[x].l = l; node[x].r = r; node[x].lazy = node[x].R = 0;
if (l == r) {
double tmp;
scanf("%lf", &tmp);
node[x].x = 0.0;
node[x].y = tmp;
return;
}
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
pushup(x);
} void add(int l, int r, int v, int x = 0) {
if (node[x].l >= l && node[x].r <= r) {
node[x].gao(v);
return;
}
int mid = (node[x].l + node[x].r) / 2;
pushdown(x);
if (l <= mid) add(l, r, v, lson(x));
if (r > mid) add(l, r, v, rson(x));
pushup(x);
} int query(int v, int x = 0) {
if (node[x].l == node[x].r)
return node[x].R;
int mid = (node[x].l + node[x].r) / 2;
int ans = 0;
pushdown(x);
if (v <= mid) ans += query(v, lson(x));
if (v > mid) ans += query(v, rson(x));
pushup(x);
return ans;
} int main() {
int bo = 0;
for (int i = -360; i <= 360; i++) {
COS[i + 360] = cos(i / 180.0 * PI);
SIN[i + 360] = sin(i / 180.0 * PI);
}
while (~scanf("%d%d", &n, &m)) {
if (bo) printf("\n");
else bo = 1;
build(1, n);
int s, a;
while (m--) {
scanf("%d%d", &s, &a);
int a1 = query(s);
int a2 = query(s + 1);
int ang = ((a1 - a2 + a + 180) % 360 + 360) % 360;
add(s + 1, n, ang);
printf("%.2lf %.2lf\n", node[0].x, node[0].y);
}
}
return 0;
}
POJ 2991 Crane(线段树+计算几何)的更多相关文章
- [poj 2991]Crane[线段树表示向量之和,而非数量]
题意: 起重机的机械臂, 由n段组成, 对某一些连接点进行旋转, 询问每次操作后的末端坐标. 思路: 由于旋转会影响到该点之后所有线段的角度, 因此容易想到用线段树记录角度, 成段更新. (但是不是每 ...
- POJ 2991 Crane
线段树+计算几何,区间更新,区间求和,向量旋转. /* *********************************************** Author :Zhou Zhentao Ema ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- Buy Tickets POJ - 2828 思维+线段树
Buy Tickets POJ - 2828 思维+线段树 题意 是说有n个人买票,但是呢这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(线段树)
Crane Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7687 Accepted: 2075 Special J ...
- 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【线段树+几何】
题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...
随机推荐
- Ubuntu 14.04下安装GitLab指南
摘要 GitLab 是一个用于仓库管理系统的开源项目.使用Git作为代码管理工具,并在此基础上搭建起来的web服务. 在GitLab的官方网站上面对Ubuntu的支持也是很好的,有比较详尽的安装指南. ...
- linux服务之NFS和SAMBA服务
这几种网络文件传输最适合局域网.网络中用FTP 一:NFS服务 nfs(network file system)网络文件系统,改服务依赖于rpcbind服务.client通过rpc訪问server端的 ...
- Android 代码混淆
什么是代码混淆 Java 是一种跨平台的.解释型语言,Java 源代码编译成中间”字节码”存储于 class 文件中.由于跨平台的需要,Java 字节码中包括了很多源代码信息,如变量名.方法名,并且通 ...
- Linux系统中如何添加自己的库文件路径
库文件在连接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的.一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径,所以使用 ...
- 查看ORACLE事务隔离级别方法(转)
众所周知,事务的隔离级别有序列化(serializable),可重复读(repeatable read),读已提交(read committed),读未提交(read uncommitted).根据隔 ...
- boost::property_tree读取解析ini文件--推荐
boost::property_tree读取解析ini文件 #include "stdafx.h" #include <iostream> #include <b ...
- 【linux】内核+文件系统下载到开发板
K开发 欢迎转载,转载时请保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:htt ...
- PHP学习之-数据库操作
PHP学习之-数据库操作 1.PHP支持那些数据库 PHP通过安装相应的扩展来实现数据库操作,现代应用程序的设计离不开数据库的应用,当前主流的数据库有MsSQL,MySQL,Sybase,Db2,Or ...
- 基于visual Studio2013解决C语言竞赛题之1090测量重量
题目 解决代码及点评 /************************************************************************/ /* ...
- 499 - What's The Frequency, Kenneth?
What's The Frequency, Kenneth? #include <stdio.h> main() { int i; char *suffix[]= { "st ...