hnu_13268 Navigition Problem

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

double calc(double x1,double y1,double x2,double y2)   //计算两点间的距离
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
    double x,y,x1,y1;
    int n;
    double dist;
    while(~scanf("%d%lf",&n,&dist))
    {
        scanf("%lf%lf",&x,&y);
        double sum=0;   //上一个输出的点到该点的距离
        int flag=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf",&x1,&y1);
            double ans=calc(x,y,x1,y1);
            sum+=ans;
            if(sum>=dist)   //浮点数相等不应该直接这样表示,运气好A了。。
            {
                printf("%.2f,%.2f\n",x+(x1-x)*(dist-(sum-ans))/ans,y+(y1-y)*(dist-(sum-ans))/ans);
                flag=1;  //只要输出过一次,就存在这样的点
                double cost=dist-(sum-ans);
                sum-=dist;
                while(sum>=dist)    //两点间距离比较长,可以输出多个点
            {
                printf("%.2f,%.2f\n",x+(x1-x)*(cost+dist)/ans,y+(y1-y)*(cost+dist)/ans);
                sum-=dist;
                cost+=dist;
            }
                x=x1; y=y1;   //(x,y),(x1,y1) 滚动使用
            }


            else 
            {
                x=x1; y=y1;
            }
        }
        if(!flag) printf("No Such Points.\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值