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【线段树+几何】
题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...
随机推荐
- Android dialog 问题
1.dialog.dismiss和dialog.cancel的区别 Cancel the dialog. This is essentially the same as calling dismiss ...
- [置顶] getline函数-linux
头文件: #include <stdio.h> 函数: ssize_t getline(char **lineptr, size_t *n, FILE *stream); eg: ssiz ...
- 获取CPU序列号
public string GetCPUSerialNo() { string cpuSerialNo = string.Empty; ManagementClass managementClass ...
- Ormlite自定义db的位置和自动更新问题
先说说以下为测试代码,有点乱,大家讲究着看.以下例子都是采用的ormlite的框架. 第一步,自定义数据库的位置: 建议一个类DatabaseHelper 继承 OrmLiteSqliteOpenHe ...
- java BigDecimal的使用和四舍五入及格式规范(精准数据)
• Java中的简单浮点数类型float和double不能够进行运算.不光是Java,在其它很多编程语言中也有这样的问题. 如果我们编译运行下面这个程序会看到什么? public class T ...
- Integer ==与Equals【原创】
package Equals; public class IntegerEquals { public static void main(String[] args) { printLine(128) ...
- 用c++开发基于tcp协议的文件上传功能
用c++开发基于tcp协议的文件上传功能 2005我正在一家游戏公司做程序员,当时一直在看<Windows网络编程> 这本书,把里面提到的每种IO模型都试了一次,强烈推荐学习网络编程的同学 ...
- Cocos2d-x教程(30)-3.x版本号物理引擎的使用
转载时请注明原文出处 : http://blog.csdn.net/u012945598/article/details/38417333 在Cocos2d-x 2.x的版本号中,开发人员能够直接使用 ...
- (摘录)MSMQ的简单介绍
MSMQ(MicroSoft Message Queue,微软消息队列)是在多个不同的应用之间实现相互通信的一种异步传输模式,相互通信的应用可以分布于同一台机器上,也可以分布于相连的网络空间中的任 ...
- MFC 关于对话框的注意点
1.对于模态对话框而言,单击确定以后对话框窗口对象即被销毁了,而对于非模态对话框来说,对话框的对象并未销毁而是隐藏起来(EndDialog函数),因此对于非模态对话框,必须重写OnOK这个虚函数,并在 ...