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 has been determine, the next important task is to set the location of 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 are p1 p2 p3 ... pn, in the order of walking direction.

Now FatMouse wants to set m CPs on the route in such way that the walking distance between adjacent CPs are all equal. You can treat the starting point as the CP0 and the end as CPm+1.

Input

There are multiple test cases. The first line of each case contains two integer n, m(1 <= n, m <= 1000). Then n pairs of integer followed, giving the coordinate of pi.

Output

The first line of each case, output "Route case_number", Then m lines followed, the ith line contains "CPcase_num: (xi, yi)" where (xi, yi) represent the coordinate of the CPi. Always keep three number after the decimal point.

Sample Input

3 3
1 1
2 3
3 5

Sample Output

Route 1
CP1: (1.026, 1.051)
CP2: (1.684, 2.368)
CP3: (2.342, 3.684)

题意:比赛时看不懂。。。英语好烂。。。原点为起点(CP0),从起点出发走到终点(Pn),途径P1,p2,p3...pn,在这条路上要设置检查站。相邻的检查站之间距离要相等。原点是给出的第一个检查站位置。
难点:一开始用斜率公式dx,由于斜率k和斜边距离都是正值,所以dx永远是正值,可是dx会出现为负值的情况。并且也存在斜率不存在的情况。
所以改用相似三角形可以解决。
 #include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define maxm 400007
#define maxn 1000+5 using namespace std;
int n,m;
struct Node
{
double x;
double y;
};
Node node[maxn];
double a[maxm];
double dx[maxn];
double dy[maxn];
double dis[maxn];
int main()
{
int cnt=;
while(~scanf("%d%d",&n,&m))
{
double sum=;
node[].x=;
node[].y=;
a[]=;
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&node[i].x,&node[i].y);
dx[i]=node[i].x-node[i-].x;
dy[i]=node[i].y-node[i-].y;
dis[i]=sqrt((node[i].x-node[i-].x)*(node[i].x-node[i-].x)+(node[i].y-node[i-].y)*(node[i].y-node[i-].y));
sum+=dis[i];
dx[i]/=dis[i];
dy[i]/=dis[i];
a[i]=sum;
}
double d=sum/(m+);
double t=d;
printf("Route %d\n",++cnt);
int num=;
for(int i=;i<=m;i++)
{
for(int i=;i<=n;i++)
if(a[i-]<d&&d<=a[i])
{ double d1=d-a[i-];
double x1=d1*dx[i]+node[i-].x;
double y1=d1*dy[i]+node[i-].y;
printf("CP%d: (%.3lf, %.3lf)\n",++num,x1,y1);
d+=t;
break;
} } }
return ;
}

ZOJ3414Trail Walk(计算几何)的更多相关文章

  1. POJ 2031 Building a Space Station (计算几何+最小生成树)

    题目: Description You are a member of the space station engineering team, and are assigned a task in t ...

  2. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

  3. python os.walk()

    os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...

  4. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. LYDSY模拟赛day1 Walk

    /* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...

  6. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  7. How Google TestsSoftware - Crawl, walk, run.

    One of the key ways Google achievesgood results with fewer testers than many companies is that we ra ...

  8. poj[3093]Margaritas On River Walk

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

  9. os.walk()

    os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. walk()方法语法格式如下: os.walk(top[, topdown=True[, onerror=None[ ...

随机推荐

  1. Lowest Common Ancestor of a Binary Search Tree 解答

    Question Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes ...

  2. 精确覆盖DLX算法模板

    代码 struct DLX { int n,id; int L[maxn],R[maxn],U[maxn],D[maxn]; ]; ) //传列长 { n=nn; ;i<=n;i++) U[i] ...

  3. OpenWrt刷机

    http://blog.163.com/l1_jun/blog/static/14386388201441344612/ http://blog.chinaunix.net/uid-25073805- ...

  4. qt model/view 架构自定义模型之QFileSystemModel

    # -*- coding: utf-8 -*- # python:2.x #QFileSystemModel """ Qt  内置了两种模型:QStandardItemM ...

  5. Ajax发送Post请求

    Ajax发送post请求与发送get请求大致类似.以下看详细实例.首先看JSP显示页面: <form action="servlet/LoginServlet" method ...

  6. fragment的入门DEMO

    效果图: 代码如下: 1.main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  7. unity4.x for mac破解(含Unity全版本号破解)

    声明,破解方式及工具,均来源于国外互联网.仅供交流学习使用! 国外一个大仙做的破解.这位大侠实在是牛,全版本号跟进,win和mac的破解包都有.win下有类似于注冊机的Patch,mac下有crack ...

  8. poj3358数论(欧拉定理)

    http://poj.org/problem?id=3358 (初始状态为分数形式)小数点进制转换原理:n / m ; n /= gcd( n , m ) ; m/= gcd( n , m ) ; n ...

  9. 2016-XCTF Final-Richman

    抽时间将XCTF Final中Richman这个题总结了下.题目及ida idb所在的链接在:http://files.cnblogs.com/files/wangaohui/richman-blog ...

  10. js实现求平均数功能

    今天在项目中遇到了一个求平均值的需求,大致需求就是,页面上面有四个input框,失去焦点就计算平均值,结果保留两位小数,并输出在页面上.不多说了,直接奉上代码,如有更好思路或者想法,都欢迎大家和我讨论 ...