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. Sliding Window Maximum 解答

    Question Given an array of n integer with duplicate number, and a moving window(size k), move the wi ...

  2. HDU1841——KMP算法

    这个题..需要对KMP的模板理解的比较透彻,以前我也只是会套模板..后来才知道..之会套模板是不行的..如果不能把握模板的每一个细节`,至少能搞清楚模板的每一个模块大体是什么意思.. 题意是给出两个串 ...

  3. 数据库--PHP环境搭建

    一: 1.PHP的架构 LAMP :Linux  阿帕奇  MySQL  PHP WAMP:Linux 阿帕奇  Mysql  PHP (集成的环境搭建软件),一键搭建PHP开发环境工具 2.修改数据 ...

  4. How to check for and disable Java in OS X

    Java used to be deeply embedded in OS X, but in recent versions of the OS it's an optional install. ...

  5. 炉石传说__multiset

     炉石传说  Problem Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石传说对于刚入门的GG学长来说有点复杂,所以他决定自己开发一个简化版 ...

  6. LabView培训

    labview基础到高级官方超全完整视频教程包括数据采集,其他模块的部 分教程,废话不多说. 免费下载地址在结尾. LabVIEW 本事编程(低级)培训LabVIEW作为前辈的图形化编程言语斥地环境, ...

  7. SQLLoader6(一个或多个数据文件按条件导入不同的表)

    测试一1.创建表: SQL), col2 )); 表已创建. SQL), col2 )); 表已创建. SQL> COMMIT; 提交完成. 2.数据文件:test.txt A A A B B ...

  8. SVG Loading

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="64&qu ...

  9. JAVA加密

    [源地址http://www.iteye.com/topic/1122076/] 加密,是以某种特殊的算法改变原有的信息数据,使得未授权的用户即使获得了已加密的信息,但因不知解密的方法,仍然无法了解信 ...

  10. 并行开发学习随笔1——plinq并行

    这两天在看园友的文章 <8天玩转并行开发——第三天 plinq的使用> 对里面的第一个实例亲手实践了一下,发现了一点有意思的事情. 测试环境:.net 4.5 64位(如果是32位的,测试 ...