Poj2919 Crane
挑战程序设计竞赛的一道题
最近刚学了三角变换。于是就构造了个矩阵,没想到正是向量旋转的矩阵(不知道具体叫什么qwq
然后网上一半的题解是左闭右开的,另一部分是懒标记的。
于是便自己yy了一个左闭右闭的线段树,方法和挑战程序设计竞赛是一样的。当然代码不是一样的
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
const double PI=3.1415926535897931;//M_Pi poj用不了
const int maxn=10101;
struct node
{
double x;
double y;
double dir;//右儿子旋转的角度
};
node T[maxn<<2];
int L[maxn];
double pre[maxn];
void build(int R,int l,int r)
{
T[R].dir=0;//多组数据,然后我就以为只有一组,遂wa了许多次
T[R].x=0;
T[R].y=0;
if(l==r)
{
T[R].y=L[l];
return ;
}
int mid=(l+r)>>1;
build(R<<1,l,mid);
build(R<<1|1,mid+1,r);
T[R].x=T[R<<1].x+T[R<<1|1].x;
T[R].y=T[R<<1].y+T[R<<1|1].y;
return ;
}
void change(int R,int l,int r,int s,double D)
{
if(s>r||s<l) return ;//所修改的向量不在当前区间
if(l==r)//正是一个点
{ //直接修改
double s=sin(D),c=cos(D),X=T[R].x,Y=T[R].y;
T[R].x=c*X-s*Y;
T[R].y=s*X+c*Y;
//printf("%lf,%lf",T[R].x,T[R].y);
return ;
}
int mid=(l+r)>>1,Ls=R<<1,Rs=R<<1|1;
change(Ls,l,mid,s,D);
change(Rs,mid+1,r,s,D);
if(s<=mid) T[R].dir+=D;//因为两端都是闭的,所以是大于等于号
double S=sin(T[R].dir),C=cos(T[R].dir);
T[R].x=T[Ls].x+(C*T[Rs].x-S*T[Rs].y);
T[R].y=T[Ls].y+(S*T[Rs].x+C*T[Rs].y);//一样的方法
return ;
}
int main()
{
//printf("%.16lf",PI);
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=n;i++) scanf("%d",&L[i]),pre[i]=PI;
build(1,1,n);
for(int i=1,a,b;i<=m;i++)
{
scanf("%d%d",&a,&b);
double D=1.0*b/180*PI;
change(1,1,n,a+1,D-pre[a+1]);
pre[a+1]=D;
printf("%.2lf %.2lf\n",T[1].x,T[1].y);
}
}
return 0;
}
Poj2919 Crane的更多相关文章
- 塔吊力矩限制器,塔吊黑匣子,塔吊电脑,tower crane
塔机力矩限制器,tower crane 适用于各种类型的固定臂塔机和可变臂塔机 塔机力矩限制器是塔式起重机机械的安全保护装置,本产品采用32位高性能微处理器为硬件平台,软件算法采用国内最先进的三滑轮取 ...
- Docker管理面板Crane开源了!
导读 数人云容器管理面板 Crane 开源啦!Crane 包含着数人云工程师对 Docker 最新技术的热爱和实践.希望借助开源社区的力量,让 Crane 完善自身,更好地成长起来,让更多的国内用户体 ...
- POJ 2991 Crane(线段树+计算几何)
POJ 2991 Crane 题目链接 题意:给定一个垂直的挖掘机臂.有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标 思路:线段树.把每一段当成 ...
- (中等) POJ 2991 Crane , 几何+线段树。
Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...
- poj2991 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 ...
- 【27.22%】【poj2991】Crane
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5772 Accepted: 1571 Special Judge D ...
- POJ - 2991 Crane (段树+计算几何)
Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...
随机推荐
- 四、jdbctemplate使用
这里使用mysql数据库,省略数据库创建过程 1.添加依赖 <!--jdbc--> <dependency> <groupId>org.springframewor ...
- 三、thymeleaf的使用
1.简介 thymleaf是一个基于html的页面模板,springboot极力推荐使用它,代替jsp. API地址:https://www.thymeleaf.org/doc/tutorials/3 ...
- spring实现固定时间定时器
此文章是基于 搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台 一. jar包介绍 1. spring-framework-4.3.4.RELEASE 的 lib ...
- 反汇编调试Android
https://code.google.com/p/android/issues/detail?id=73076 http://my.unix-center.net/~Simon_fu/?p=527 ...
- wget http://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz 下载时报错 ssl is required 解决办法
方法一:使用浏览器下载.在浏览器中输入 http://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz 方法二:将h ...
- BZOJ4698: Sdoi2008 Sandy的卡片(后缀数组 二分)
题意 题目链接 Sol 不要问我为什么发两篇blog,就是为了骗访问量 后缀数组的也比较好想,先把所有位置差分,然后在height数组中二分就行了 数据好水啊 // luogu-judger-enab ...
- git push报错--私钥问题
输入git push -u origin master时提示 Permission denied (publickey). fatal: Could not read from remote repo ...
- Linux基础之-正则表达式(grep,sed,awk)
一. 正则表达式 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式是对字符串操作的一种逻辑公 ...
- SQLServer中取当前年,月,日,时,分,秒
Select GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName(month,GetDate()) as '月',DateName ...
- python 小词云
# Author:Alex.wang# Date:2017.06.02# Version:3.6.0 import matplotlib.pyplot as pltfrom wordcloud imp ...