1549: Navigition Problem (幾何計算+模擬 細節較多)
1549: Navigition Problem
Time Limit: 1 Sec Memory Limit: 256 Mb Submitted: 400 Solved: 122
Description
Navigation is a field of study that focuses on the process of monitoring and controlling the movement of a craft or vehicle from one place to another. The field of navigation includes four general categories: land navigation, marine navigation, aeronautic navigation, and space navigation. (From Wikipedia)
Input
The input file contains multiple test cases.
For each test case,the first line contains an interger N and a real number DIST. The following N+1 lines describe the road information.
You should proceed to the end of file.
Hint:
1 <= N <= 1000
0 < DIST < 10,000
Output
For each the case, your program will output all the positions where the Navigition APP should re-initiate geographic location. Output “No Such Points.” if there is no such postion.
Sample Input
2 0.50 0.00 0.00 1.00 0.00 1.00 1.00
Sample Output
0.50,0.00 1.00,0.00 1.00,0.50 1.00,1.00題目意思:
給你很多點,將這些點連成線段,起點和終點不相連
從起點出發,沿著這些折線走,每一次走d距離
問你每走d距離達到的所有點的坐標
(包括起點和終點) 分析:
就是幾何計算+模擬,細節多,每沿著折線走d距離,就是輸出一下到達該點的坐標
總長度不足d
就按照題目輸出字符串
下一步走d距離超過了終點的話
最後只要輸出終點
不用輸出超出終點的點
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algorithm> #include<vector> #include<map> #include<cctype> #include<stack> #include<sstream> #include<list> #include<assert.h> #include<bitset> #include<numeric> using namespace std; typedef long long LL; #define max_v 1005 struct node { double x,y; }p[max_v]; double len[max_v]; double dis(node a,node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double sum[max_v]; int main() { int n; double d; while(~scanf("%d %lf",&n,&d)) { double c=0; sum[0]=0; for(int i=1;i<=n+1;i++) { scanf("%lf %lf",&p[i].x,&p[i].y); if(i>1) { len[i-1]=dis(p[i],p[i-1]); c+=len[i-1]; sum[i-1]=sum[i-2]+len[i-1]; } } if(c<d) { printf("No Such Points.\n"); continue; } double now=0,k,x,y; for(int i=1;i<=n;) { if(now+d<=sum[i]) { double L=now+d-sum[i-1]; double x1=p[i].x; double y1=p[i].y; double x2=p[i+1].x; double y2=p[i+1].y; if(x1!=x2) { k=(y1-y2)/(x1-x2); if(x2<x1) { x=x1-sqrt((L*L)/(k*k+1)); y=k*(x-x1)+y1; }else { x=x1+sqrt((L*L)/(k*k+1)); y=k*(x-x1)+y1; } }else { x=x1; if(y2<y1) y=y1-L; else y=y1+L; } printf("%.2lf,%.2lf\n",x,y); now=now+d; }else { i++; } } } return 0; } /* 題目意思: 給你很多點,將這些點連成線段,起點和終點不相連 從起點出發,沿著這些折線走,每一次走d距離 問你每走d距離達到的所有點的坐標 (包括起點和終點) 分析: 就是幾何計算+模擬,細節多,每沿著折線走d距離,就是輸出一下到達該點的坐標 總長度不足d 就按照題目輸出字符串 下一步走d距離超過了終點的話 最後只要輸出終點 不用輸出超出終點的點 */
1549: Navigition Problem (幾何計算+模擬 細節較多)