1549: Navigition Problem (几何计算+模拟 细节较多)

1549: Navigition Problem

Submit Page    Summary    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.\n");
             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\n",x,y);
                now=now+d;
            }else
            {
                i++;
            }
        }
    }
    return 0;
}
/*
题目意思:
给你很多点,将这些点连成线段,起点和终点不相连
从起点出发,沿着这些折线走,每一次走d距离
问你每走d距离达到的所有点的坐标
(包括起点和终点)

分析:
就是几何计算+模拟,细节多,每沿着折线走d距离,就是输出一下到达该点的坐标
总长度不足d
就按照题目输出字符串
下一步走d距离超过了终点的话
最后只要输出终点
不用输出超出终点的点

*/


原文地址:https://www.cnblogs.com/yinbiao/p/9498593.html

时间: 2024-10-13 04:50:35

1549: Navigition Problem (几何计算+模拟 细节较多)的相关文章

csu 1549: Navigition Problem(几何,模拟)

1549: Navigition Problem Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 305  Solved: 90[Submit][Status][Web Board] Description Navigation is a field of study that focuses on the process of monitoring and controlling the movement of a craft or vehicle

CSUOJ 1549 Navigition Problem

1549: Navigition Problem Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 65  Solved: 12 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.

UVALive 6092 Catching Shade in Flatland --枚举+几何计算

题意:x=[-200,200],y=[-200,200]的平面,一天中太阳从不同角度射到长椅(原点(0,0))上,有一些树(用圆表示),问哪个时刻(分钟为单位)太阳光线与这些圆所交的弦长总和最长.太阳距离原点总是500m.(这些圆不会互相相交,每个圆都不包括原点或者不经过原点) 解法:直接暴力24*60分钟,找出此时的角度,然后求出直线方程,再枚举每个圆,求出弦长.注意这里每个圆都不包括原点,所以直线与圆的交点一定在同一侧,所以..我当时想多了,没看清题目.把他当成可以包含原点了,代码超长,幸好

HDU 5186 zhx&#39;s submissions 模拟,细节 难度:1

http://acm.hdu.edu.cn/showproblem.php?pid=5186 题意是分别对每一位做b进制加法,但是不要进位 模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全部去掉 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=101; const int maxm=201; int n,b; char

NYOJ 179 LK&#39;s problem (排序模拟)

链接:click here~~ 题意: 描述 LK has a question.Coule you help her? It is the beginning of the day at a bank, and a crowd  of clients is already waiting for the entrance door to  open. Once the bank opens, no more clients arrive, and  tellerCount tellers be

xFlow 2014 build 92 Win64 1CD流体动力学(CFD)计算模拟软件

xFlow 2014 build 92 Win64 1CD流体动力学(CFD)计算模拟软件 流体模拟软件 NextLimit.RealFlow.2014.v8.1.1.0179.Win64 1CDXFlow是一款强大的软件,使用具有专利的基于粒子.完整拉格朗日函数,能够在工程.设计.科学和建筑领域简单的处理传 统的复杂计算流体动力学(CFD)问题.XFlow具有仿真模拟气体和液体流动.热量和质量转移.移动体.多相物理学.声学 和流体结构作用的能力.■□■□■□■□■□■□■□■□■□■□■□■□

[LeetCode] 数学计算模拟类问题:除法和幂,注意越界问题。题 Pow(x, n) ,Divide Two Integers

引言 数学计算的模拟类题目,往往是要求实现某种计算(比如两数相除),实现的过程中会有所限定,比如不允许乘法等等. 这类题目首先要注意计算过程中本身的特殊情况.比如求相除,则必须首先反映过来除数不能为0. 其次要记得考虑负数的情况,如果计算范围不单单是整数,还要考虑double的比较方式. 最后要注意越界情况,这个是最容易犯错的,只能具体问题具体分析. 例题 1 Pow(x, n) Implement pow(x, n). class Solution { public: double pow(d

hdu5402 Travelling Salesman Problem(棋盘染色+模拟)

题目: Travelling Salesman Problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 906    Accepted Submission(s): 331 Special Judge Problem Description Teacher Mai is in a maze with n rows and m c

hdu 2206 IP的计算 模拟

IP的计算 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7980    Accepted Submission(s): 1570 Problem Description 在网络课程上,我学到了很多有关IP的知识.IP全称叫网际协议,有时我们又用IP来指代我们的IP网络地址,现在IPV4下用一个32位无符号整数来表示,一般用点分方式来