zoukankan      html  css  js  c++  java
  • 1549: Navigition Problem (几何计算+模拟 细节较多)

    1549: Navigition Problem

          Time Limit: 1 Sec     Memory Limit: 256 Mb     Submitted: 400     Solved: 122    


    Description

    Navigation is a field of study that focuses on the process of monitoring and controlling the movement of a craft or vehicle from one place to another. The field of navigation includes four general categories: land navigation, marine navigation, aeronautic navigation, and space navigation. (From Wikipedia)
    Recently, slowalker encountered a problem in the project development of Navigition APP. In order to provide users with accurate navigation service , the Navigation APP should re-initiate geographic location after the user walked DIST meters. Well, here comes the problem. Given the Road Information which could be abstracted as N segments in two-dimensional space and the distance DIST, your task is to calculate all the postion where the Navigition APP should re-initiate geographic location.

    Input

    The input file contains multiple test cases.
    For each test case,the first line contains an interger N and a real number DIST. The following N+1 lines describe the road information.
    You should proceed to the end of file.

    Hint:
    1 <= N <= 1000
    0 < DIST < 10,000

    Output

    For each the case, your program will output all the positions where the Navigition APP should re-initiate geographic location. Output “No Such Points.” if there is no such postion.

    Sample Input

    2 0.50
    0.00 0.00
    1.00 0.00
    1.00 1.00

    Sample Output

    0.50,0.00
    1.00,0.00
    1.00,0.50
    1.00,1.00

    题目意思:
    给你很多点,将这些点连成线段,起点和终点不相连
    从起点出发,沿着这些折线走,每一次走d距离
    问你每走d距离达到的所有点的坐标
    (包括起点和终点)
    分析:
    就是几何计算+模拟,细节多,每沿着折线走d距离,就是输出一下到达该点的坐标
    总长度不足d
    就按照题目输出字符串
    下一步走d距离超过了终点的话
    最后只要输出终点
    不用输出超出终点的点
     
    #include<cstdio>
    #include<string>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<cctype>
    #include<stack>
    #include<sstream>
    #include<list>
    #include<assert.h>
    #include<bitset>
    #include<numeric>
    using namespace std;
    typedef long long LL;
    #define max_v 1005
    struct node
    {
        double x,y;
    }p[max_v];
    double len[max_v];
    double dis(node a,node b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    double sum[max_v];
    int main()
    {
        int n;
        double d;
        while(~scanf("%d %lf",&n,&d))
        {
            double c=0;
            sum[0]=0;
            for(int i=1;i<=n+1;i++)
            {
                scanf("%lf %lf",&p[i].x,&p[i].y);
                if(i>1)
                {
                    len[i-1]=dis(p[i],p[i-1]);
                    c+=len[i-1];
                    sum[i-1]=sum[i-2]+len[i-1];
                }
            }
            if(c<d)
            {
                 printf("No Such Points.
    ");
                 continue;
            }
            double now=0,k,x,y;
            for(int i=1;i<=n;)
            {
                if(now+d<=sum[i])
                {
                    double L=now+d-sum[i-1];
                    double x1=p[i].x;
                    double y1=p[i].y;
                    double x2=p[i+1].x;
                    double y2=p[i+1].y;
    
                    if(x1!=x2)
                    {
                        k=(y1-y2)/(x1-x2);
                        if(x2<x1)
                        {
                            x=x1-sqrt((L*L)/(k*k+1));
                            y=k*(x-x1)+y1;
                        }else
                        {
                            x=x1+sqrt((L*L)/(k*k+1));
                            y=k*(x-x1)+y1;
                        }
                    }else
                    {
                        x=x1;
                        if(y2<y1)
                            y=y1-L;
                        else
                            y=y1+L;
                    }
                    printf("%.2lf,%.2lf
    ",x,y);
                    now=now+d;
                }else
                {
                    i++;
                }
            }
        }
        return 0;
    }
    /*
    题目意思:
    给你很多点,将这些点连成线段,起点和终点不相连
    从起点出发,沿着这些折线走,每一次走d距离
    问你每走d距离达到的所有点的坐标
    (包括起点和终点)
    
    分析:
    就是几何计算+模拟,细节多,每沿着折线走d距离,就是输出一下到达该点的坐标
    总长度不足d
    就按照题目输出字符串
    下一步走d距离超过了终点的话
    最后只要输出终点
    不用输出超出终点的点
    
    */


  • 相关阅读:
    ORA-12520: TNS:监听程序无法为请求的服务器类型找到可用的处理程序解
    Django2.1.2创建默认管理后台
    堡垒机实例以及数据库操作
    pycharm常用快捷键
    Linux命令之sftp
    oracle收集ash和awr性能报告方法
    linux-php5.6-安装sftp扩展
    linux系统安全设置策略
    Openssh版本升级修复漏洞
    Android Studio下HierarchyViewer的使用
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9498593.html
Copyright © 2011-2022 走看看