日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVA 11796

發(fā)布時(shí)間:2025/3/14 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVA 11796 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:? 有兩個(gè)狗, 按照 多邊形跑,不知道兩條狗的速度,但是狗是同時(shí)出發(fā),同時(shí)到達(dá)終點(diǎn)的

????????? 輸出兩條狗的 最大相距距離 - 最小相距距離;

思路 : 用物理的相對運(yùn)動(dòng)來計(jì)算, 每次只計(jì)算 兩條狗的直線運(yùn)動(dòng), 轉(zhuǎn)折點(diǎn)再額外更新

LRJ 模板大法好 !!!LRJ 模板大法好 !!!!LRJ 模板大法好 !!!!

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 100; const double eps = 1e-9;struct Point {double x , y;Point (double x = 0, double y = 0) : x(x),y(y) {} };typedef Point Vector;int dcmp (double x) { if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; }Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x,A.y+B.y); } Vector operator - (Point A, Point B) { return Vector(A.x-B.x,A.y-B.y); } Vector operator * (Vector A, double p) { return Vector(A.x*p,A.y*p); } Vector operator / (Vector A, double p) { return Vector(A.x/p,A.y/p); } bool operator < (const Point &a, const Point &b) {return a.x < b.x || (a.x == b.x && a.y < b.y); } bool operator == (const Point &a, const Point &b) {return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; }double Dot (Vector A,Vector B) { return A.x*B.x + A.y*B.y; } double Length (Vector A) { return sqrt(Dot(A,A)); } double Angle (Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); } double Cross (Vector A, Vector B) { return A.x*B.y - A.y*B.x; } double DistanceToSegment (Point P, Point A, Point B) { ///點(diǎn)到線段的距離if(A == B) return Length(P - A);Vector v1 = B - A, v2 = P - A, v3 = P - B;if(dcmp(Dot(v1,v2)) < 0 ) return Length(v2);else if(dcmp(Dot(v1,v3)) > 0) return Length(v3);else return fabs(Cross(v1,v2)) / Length(v1); }double MAX,MIN;void UpDate(Point P, Point A, Point B) {MIN = min(MIN, DistanceToSegment(P,A,B)); ///當(dāng)前 和 點(diǎn) 到線段的最小距離MAX = max(Length(P-A),MAX);MAX = max(Length(P-B),MAX); }Point Pa[maxn], Pb[maxn];int main() {int t;scanf("%d",&t);for(int kase = 1; kase <= t; kase++){int A, B;scanf("%d %d",&A,&B);for(int i = 0; i < A; ++i) cin >> Pa[i].x >> Pa[i].y;for(int i = 0; i < B; ++i) cin >> Pb[i].x >> Pb[i].y;double LenA = 0, LenB = 0;for(int i = 0; i < A-1; ++i) LenA += Length(Pa[i] - Pa[i+1]);for(int i = 0; i < B-1; ++i) LenB += Length(Pb[i] - Pb[i+1]);MAX = -1e9; MIN = 1e9;int sa = 0, sb = 0; ///下一個(gè)轉(zhuǎn)折點(diǎn)Point Na = Pa[0], Nb = Pb[0]; /// 起始位置while(sa < A-1 && sb < B-1){double La = Length(Pa[sa+1] - Na); /// a 當(dāng)前到下一個(gè)轉(zhuǎn)折點(diǎn)的長度double Lb = Length(Pb[sb+1] - Nb); /// b ...double t = min(La / LenA, Lb / LenB); /// 運(yùn)動(dòng)的時(shí)間Vector Va = (Pa[sa+1] - Na) / La * t * LenA;/// a 的位移量Vector Vb = (Pb[sb+1] - Nb) / Lb * t * LenB;/// b 的位移量UpDate(Na,Nb,Nb+Vb-Va); /// B相對A 的運(yùn)動(dòng)就是 NB + Vb - Va;Na = Na + Va; /// 更新 a 的當(dāng)前點(diǎn)Nb = Nb + Vb;if(Na == Pa[sa+1]) sa++; ///如果到了轉(zhuǎn)折點(diǎn), sa 下一個(gè)轉(zhuǎn)折點(diǎn)更新if(Nb == Pb[sb+1]) sb++;}printf("Case %d: %.0lf\n",kase, MAX - MIN);}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/aoxuets/p/5506893.html

總結(jié)

以上是生活随笔為你收集整理的UVA 11796的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。