Trail Walk Time limit: 2 Seconds Memory Limit: 65536 KB
Fatmouse is busy organizing the coming trail walk. After the route for the trail walk have been determine, the next important task is to set the location of the CPs (check point).
The route is composed by n line segments which only intersect on their endpoints. Set The starting point of the trail walk as origin, the coordinate of the endpoints is p1 p2 p3 ... PN, in the order of walking direction.
Now Fatmouse wants to set M. CPS on the route in such the same as the walking distance between adjacent CPs is all E Qual. You can treat the starting point as the CP0 and the end as cpm+1.
Input
There is multiple test cases. The first line of all case contains- n, m(1 <= n, M <= 1000). Then n pairs of integer followed, giving the coordinate of Pi.
Output
The first line of all case, output "Route case_number", then m lines followed, the i-th line Co Ntains "CPcase_num: (Xi, Yi)" where (Xi, Yi) represent the coordinate of the CPi. Always keep three number after the decimal point.
Sample Input
3 31 12) 33 5
Sample Output
Route 1CP1: (1.026, 1.051) CP2: (1.684, 2.368) CP3: (2.342, 3.684)
Test instructions: I can't read the game ... The English is so rotten ... The origin is the starting point (CP0), from the starting point to the end point (Pn), the way P1,p2,p3...pn, on this road to set up checkpoints. The distances between adjacent checkpoints are equal. The origin point is the first checkpoint location given.
Difficulty: The first use of the slope formula DX, because the slope K and hypotenuse distance are positive, so DX is always positive, but the DX will appear negative. And there is a situation where the slope does not exist.
So the use of similar triangles can be solved.
1#include <cstdio>2#include <iostream>3#include <cstdlib>4#include <algorithm>5#include <ctime>6#include <cmath>7#include <string>8#include <cstring>9#include <stack>Ten#include <queue> One#include <list> A#include <vector> -#include <map> -#include <Set> the #defineLL Long Long - #defineINF 0x3f3f3f3f - #definePI 3.1415926535897932384626 - #defineEPS 1e-10 + #defineMAXM 400007 - #defineMAXN 1000+5 + A using namespacestd; at intn,m; - structNode - { - Doublex; - Doubley; - }; in Node NODE[MAXN]; - DoubleA[MAXM]; to DoubleDX[MAXN]; + DoubleDY[MAXN]; - DoubleDIS[MAXN]; the intMain () * { $ intCnt=0;Panax Notoginseng while(~SCANF ("%d%d",&n,&m)) - { the Doublesum=0; +node[0].x=0; Anode[0].y=0; thea[0]=0; + for(intI=1; i<=n;i++) - { $scanf"%LF%LF",&node[i].x,&node[i].y); $dx[i]=node[i].x-node[i-1].x; -dy[i]=node[i].y-node[i-1].y; -Dis[i]=sqrt ((node[i].x-node[i-1].x) * (node[i].x-node[i-1].x) + (node[i].y-node[i-1].Y) * (node[i].y-node[i-1].y)); thesum+=Dis[i]; -Dx[i]/=Dis[i];WuyiDy[i]/=Dis[i]; thea[i]=sum; - } Wu Doubled=sum/(m+1); - Doublet=D; Aboutprintf"Route%d\n",++CNT); $ intnum=0; - for(intI=1; i<=m;i++) - { - for(intI=1; i<=n;i++) A if(a[i-1]<d&&d<=A[i]) + { the - Doubled1=d-a[i-1]; $ Doublex1=d1*dx[i]+node[i-1].x; the Doubley1=d1*dy[i]+node[i-1].y; theprintf"cp%d: (%.3LF,%.3lf) \ n",++num,x1,y1); thed+=T; the Break; - } in the } the About } the return 0; the}
Zoj3414trail Walk (Computational geometry)