1549: Navigition Problem

Time Limit: 1 Sec  Memory Limit: 256 MB
Submit: 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 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 题意:有 n 条首尾相连的线段 (第1条不和第 n条相连).从第一个点的起点开始每次沿着线段平移 d 个单位到达某一个点,把每次的坐标输出,如果所有线段之和都小于d,输出 "No Such Points."
题解:模拟这个过程,每次确定当前的点在哪条线段上,假设当前点在line[i] ,那么我们设当前点为 (x,y), 可以得到它与line[i]起点的距离,然后通过公式可以推出当前点的位置,记得讨论斜率不存在的
情况。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
const int N = ;
struct Point
{
double x,y;
} p[N];
struct Line
{
Point a,b;
} line[N];
double len[N];
double dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double sum[N];
int main()
{
int n;
double d;
while(scanf("%d%lf",&n,&d)!=EOF)
{
double SUM = ;
sum[] = ;
for(int i=; i<=n+; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
if(i>)
{
len[i-] = dis(p[i],p[i-]);
SUM+=len[i-];
sum[i-] = sum[i-]+len[i-];
}
}
if(SUM<d)
{
printf("No Such Points.\n");
continue;
}
double now = ,k,x,y;
for(int i=; i<=n;)
{
if(now+d<=sum[i])
{
double L = now+d - sum[i-];
double x1 = p[i].x,y1 = p[i].y;
double x2 = p[i+].x,y2 = p[i+].y;
if(x1!=x2)
{
k = (y1-y2)/(x1-x2);
if(x2<x1)
{
x = x1-sqrt((L*L)/(k*k+));
y = k*(x-x1)+y1;
}
else
{
x = x1+sqrt((L*L)/(k*k+));
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++;
}
} }
}

csu 1549: Navigition Problem(几何,模拟)的更多相关文章

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

    1549: Navigition Problem Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 256 Mb     Su ...

  2. CSUOJ 1549 Navigition Problem

    1549: Navigition Problem Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 65  Solved: 12 Description N ...

  3. csu 1312 榜单(模拟题)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1312 1312: 榜单 Time Limit: 1 Sec  Memory Limit: 128 ...

  4. csu - 1536: Bit String Reordering (模拟)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1536 不知道为何怎么写都写不对. 这题可以模拟. 虽然题目保证一定可以从原串变成目标串,但是不一定 ...

  5. HDOJ/HDU 1022 Train Problem I(模拟栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  6. HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. HDU 2522 A simple problem (模拟)

    题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第 ...

  9. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

随机推荐

  1. 【计算机视觉】SIFT中LoG和DoG比较

    <SIFT原理与源码分析>系列文章索引:http://www.cnblogs.com/tianyalu/p/5467813.html 在实际计算时,三种方法计算的金字塔组数noctaves ...

  2. Codeforces Round #286 (Div. 2) B 并查集

    B. Mr. Kitayuta's Colorful Graph time limit per test 1 second memory limit per test 256 megabytes in ...

  3. 折腾到死:matlab7.0 安装

    matlab7.0应该是2004年的东西了吧,装起来相当费劲!为什么不用更高的版本呢?其实我也想,之前安装的2013a安装包就5个多G,安装完之后就十多个G了.我习惯将软件安装到C盘,可怜我那100G ...

  4. HDU3400 三分套三分

    题意 就是给你两条线段AB , CD ,一个人在AB以速度p跑,在CD上以q跑, 在其他地方跑速度是r.问你从A到D最少的时间. 三分AB ,然后再三分CD ,模板题目,这题卡精度 eps不能少 #i ...

  5. 使用cron命令配置定时任务(cron jobs)

    原文 http://www.cnblogs.com/end/archive/2012/02/21/2361741.html 开机就启动cron进程的设置命令:chkconfig --add crond ...

  6. Weblogic安装与配置图文详解

    Weblogic是什么Weblogic的安装Weblogic创建域Weblogic管理域Weblogic的应用Weblogic是什么 Weblogic这是我入职以后第一次接触到的词汇,我很陌生,就从我 ...

  7. Win10环境下配置VScode的C++编译环境

    写前感想:前前后后,折腾好几次,最后还是在学长安利下,开始入坑vscode了.原因一个是小巧,还有就是vs新建工程码题的方式太消耗内存了,基本每个项目就是以MB为单位计算的,然后希望用这篇文章记录自己 ...

  8. web开发之Servlet 二

    在上一篇文章中,我们演示也证明了Servlet 是一种动态web资源开发的技术,即我可以在浏览器中输入URL,然后就可以在浏览器中看到我们编写的Servlet资源. 那当我们在浏览器上一起一个HTTP ...

  9. Codeforces Round #419 (Div. 2) A-E

    上紫啦! E题1:59压哨提交成功翻盘 (1:00就做完了调了一个小时,还好意思说出来? (逃)) 题面太长就不复制了,但是配图很可爱所以要贴过来 九条可怜酱好可爱呀 A - Karen and Mo ...

  10. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...