国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

POJ2991-Crane-線段樹+計算幾何

2019-11-08 03:04:19
字體:
來源:轉載
供稿:網友

原題鏈接 Crane Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6253 Accepted: 1673 Special Judge 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. Input

The input consists of several instances, separated by single empty lines.

The first line of each instance consists of two integers 1 ≤ n ≤10 000 and c 0 separated by a single space – the number of segments of the crane and the number of commands. The second line consists of n integers l1,…, ln (1 li 100) separated by single spaces. The length of the i-th segment of the crane is li. The following c lines specify the commands of the operator. Each line describing the command consists of two integers s and a (1 ≤ s < n, 0 ≤ a ≤ 359) separated by a single space – the order to change the angle between the s-th and the s + 1-th segment to a degrees (the angle is measured counterclockwise from the s-th to the s + 1-th segment). Output

The output for each instance consists of c lines. The i-th of the lines consists of two rational numbers x and y separated by a single space – the coordinates of the end of the n-th segment after the i-th command, rounded to two digits after the decimal point.

The outputs for each two consecutive instances must be separated by a single empty line. Sample Input

2 1 10 5 1 90

3 2 5 5 5 1 270 2 90 Sample Output

5.00 10.00

-10.00 5.00 -5.00 10.00 Source

CTU Open 2005 題意:n個棍子原來排成一列豎直向上,然后修改某處棍子與棍子之間的角度,每次修改輸出最后一根棍子的尾端的坐標 思路:每次修改都會影響到該棍子和該棍子之后所有棍子的位置,求最后一個棍子的位置,這就有些類似于線段樹更新區間和這種問題,所以問題就是找到區間和的計算方法(即計算棍子坐標的快速的方法)。而我們注意到這里線段樹的一個區間可以表示成一個向量,每一個單獨的線段其實也可以表示成一個向量,而向量V0(x1,y1)轉過角μ成V1(x2,y2)后坐標的計算有 這里寫圖片描述 然后需要一個數組記錄線段與線段之間的夾角,而對于不同的向量還要記錄其左子向量與右子向量的夾角并向上更新

#include <cstdio>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double PI = acos(-1.0);const int maxn = 10000 + 10;const int max_size = (1<<15) - 1;typedef struct vect{ double x,y,angle;//angle是左孩子向量與右孩子向量之間的角度,這與線段與線段之間的角度是不同的}vect;vect v[max_size];int n,c;int len[maxn];double nowangle[maxn];//nowangle[i]代表第i與第i+1條線段之間現在的夾角,初始值為PIvoid init(int k,int l,int r){ v[k].angle=v[k].x=0;//起初所有的向量之間的夾角都是0 if(l==r){ v[k].y=len[l]; } else{ int lch=k*2,rch=k*2+1; int mid=(l+r)/2; init(lch,l,mid); init(rch,mid+1,r); v[k].y = v[lch].y + v[rch].y; } return;}void change(int s,double a,int vloc,int l,int r){//這里的a是一個相對的變化角度 //
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 古交市| 福安市| 胶南市| 托克逊县| 平远县| 隆德县| 明星| 临猗县| 噶尔县| 玉环县| 玉树县| 枣强县| 荣成市| 阳春市| 定安县| 平舆县| 阜阳市| 阿拉善右旗| 中方县| 松溪县| 喀喇沁旗| 枞阳县| 奉贤区| 洛南县| 阜阳市| 长宁县| 和平县| 连州市| 通辽市| 邻水| 唐河县| 涪陵区| 太和县| 杭锦后旗| 囊谦县| 乳山市| 醴陵市| 汝南县| 监利县| 汶上县| 德兴市|