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. Linux 计算器

    bc: 默认没有小数位,使用scale=2设置保留的位数.

  2. UITableView 滚动时隐藏键盘

    #pragma mark - UItableView滚动时收键盘 - (void)scrollViewWillBeginDragging:(UITableView *)scrollView { [se ...

  3. Udp实现简单的聊天程序

    在<UDP通讯协议>这篇文章中,简单的说明了Udp协议特征及如何Udp协议传输数据 这里将用Udp协议技术,编写一个简单的聊天程序: //发送端: package com.shindo.j ...

  4. 格而知之15:我所理解的Block(1)

    1.Block 本质上是一个struct结构体,在这个结构体中,最重要的成员是一个函数(当然除函数外还有其他重要的成员). 2.在开始解析Block之前,首先来回顾一下Block的格式.Block相关 ...

  5. [转]Laravel 4之路由

    Laravel 4之路由 http://dingjiannan.com/2013/laravel-routing/ Laravel 4路由是一种支持RESTful的路由体系, 基于symfony2的R ...

  6. CGBitmapContextCreate函数

    CGBitmapContextCreate函数参数详解 函数原型: CGContextRef CGBitmapContextCreate ( void *data,    size_t width, ...

  7. vs连接mysql出错解决方法

    vs连接mysql出错解决方法 先按以下的步骤配置一下: **- (1)打开VC6.0 工具栏Tools菜单下的Options选项.在Directories的标签页中右边的"Show dir ...

  8. java编程中的Java.Lang.Math类

    1. Math.PI  :表示的是圆周率常量: 2.Math.E    :表示的是普通常量(e): 3.abs()方法: 表示取绝对值 eg1: int x = Math.abs(50L);     ...

  9. iOS指纹识别

    #import "ViewController.h" #import <LocalAuthentication/LocalAuthentication.h> @inte ...

  10. CMarkUp读写XML(转)

    Fast start to XML in C++ Enough bull. You want to create XML or read and find things in XML. All you ...