1549: Navigition Problem
Time Limit: 1 Sec Memory Limit: 256 MB
Submit: 65 Solved: 12
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)
Recently, slowalker encountered a problem in the project development of Navigition APP. In order to provide users with accurate navigation service , the Navigation APP should re-initiate geographic location after the user walked DIST meters. Well, here comes the problem. Given the Road Information which could be abstracted as N segments in two-dimensional space and the distance DIST, your task is to calculate all the postion where the Navigition APP should re-initiate geographic location.
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
HINT
Source
解题:此题太JB难读了,就是每次走了dist距离 然后输出此时的坐标位置,记得一定要走够dist的距离才输出坐标,还有坐标中间有逗号。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int n;
double R;
struct Point {
double x,y;
} p[maxn];
double getDis(const Point &a,const Point &b) {
double tmp = (a.x - b.x)*(a.x - b.x);
tmp += (a.y - b.y)*(a.y - b.y);
return sqrt(tmp);
}
vector<Point>ans;
int main() {
while(~scanf("%d %lf",&n,&R)) {
for(int i = ; i <= n; ++i)
scanf("%lf %lf",&p[i].x,&p[i].y);
int low = ,high = n;
Point now = p[low++];
ans.clear();
double hg = ;
while(low <= high) {
double ds = getDis(now,p[low]);
if((ds - R + hg) > 1e-) {
now.x += (p[low].x - now.x)/ds*(R-hg);
now.y += (p[low].y - now.y)/ds*(R-hg);
hg += R - hg;
}else{
hg += ds;
now = p[low++];
}
if(fabs(hg - R) < 1e-) {
ans.push_back(now);
hg = 0.0;
}
}
if(ans.size()) {
for(int i = ; i < ans.size(); ++i)
printf("%.2f,%.2f\n",ans[i].x,ans[i].y);
} else puts("No Such Points.");
}
return ;
}