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. BZOJ1089 [SCOI2003]严格n元树 【dp + 高精】

    Description 如果一棵树的所有非叶节点都恰好有n个儿子,那么我们称它为严格n元树.如果该树中最底层的节点深度为d (根的深度为0),那么我们称它为一棵深度为d的严格n元树.例如,深度为2的严 ...

  2. NOIP2015运输计划题解报告

    这题在洛谷上可以找到提交 P2680运输计划 题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航 ...

  3. 洛谷 [POI2007]BIU-Offices 解题报告

    [POI2007]BIU-Offices 题意 给定\(n(\le 100000)\)个点\(m(\le 2000000)\)条边的无向图\(G\),求这个图\(G\)补图的连通块个数. 一开始想了半 ...

  4. Linux内核分析2

    周子轩原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 本次实验是通过分析一个简单 ...

  5. 【读书笔记】《HTTP权威指南》:Web Hosting

    一.概述 从零开始构建一个真正意义的网站需要做很多事情,包括购买计算机硬件.建造机房.注册域名.购买网络带宽.开发Web服务器软件.管理网站内容等等.在互联网发展的早期,构建网站的这一系列动作通常都是 ...

  6. bzoj2734:[HNOI2012]集合选数(状压DP)

    菜菜的喵喵题~ 化序列为矩阵!化腐朽为神奇!左上角为1,往右每次*3,往下每次*2,这样子就把问题转化成了在矩阵里选不相邻的数有几种可能. 举个矩阵的例子 1 3 9 27 2 6 18 54 4 1 ...

  7. Endless Spin

    clj的题.图是假的别看 得先做这个[HAOI2015]按位或 本题如果还用[HAOI2015]按位或 的方法,2^50拜拜 但是思路一定是这样的:min-max容斥,考虑每个S的第一触及次数期望 这 ...

  8. BZOJ #3746: [POI2015]Czarnoksiężnicy okrągłego stołu 动态规划

    转载请注明出处:http://www.cnblogs.com/TSHugh/p/8823423.html 读完题就会发现p=0.1的情况以及n=1.2的情况都可以直接判掉,而p=2的时候也可以直接构造 ...

  9. bzoj 4347 [POI2016]Nim z utrudnieniem DP

    4347: [POI2016]Nim z utrudnieniem Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 733  Solved: 281[Su ...

  10. 「PLC」PLC的硬件与工作原理