csu 1549: Navigition Problem(几何,模拟)
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(几何,模拟)的更多相关文章
- 1549: Navigition Problem (几何计算+模拟 细节较多)
1549: Navigition Problem Submit Page Summary Time Limit: 1 Sec Memory Limit: 256 Mb Su ...
- CSUOJ 1549 Navigition Problem
1549: Navigition Problem Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 65 Solved: 12 Description N ...
- csu 1312 榜单(模拟题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1312 1312: 榜单 Time Limit: 1 Sec Memory Limit: 128 ...
- csu - 1536: Bit String Reordering (模拟)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1536 不知道为何怎么写都写不对. 这题可以模拟. 虽然题目保证一定可以从原串变成目标串,但是不一定 ...
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- 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 ...
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 2522 A simple problem (模拟)
题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第 ...
- HDU 5867 Water problem (模拟)
Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...
随机推荐
- 【Python3的命名空间与作用域,闭包函数,装饰器】
一.命名空间与作用域 命名空间是名字和对象的映射,就像是字典,key是变量名,value是变量的值 1.命名空间的定义 name='egon' #定义变量 def func(): #定义函数 pass ...
- SNMP-网络管理协议
SNMP协议简介: a. 轮询(Polling) -- 定时获取状态, 中断(Interrupt)--出问题通知 b. 共同体名(community) -- 口令--只读口令 --读写口令 使用SNM ...
- Communications link failure;;The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure::The ...
- C++ STL 一般总结(转载)
注:原博地址:http://www.cnblogs.com/biyeymyhjob/archive/2012/07/22/2603525.html 以下内容来源网上 经过整合而成 一.一般介绍 STL ...
- 洛谷P2398 GCD SUM (数学)
洛谷P2398 GCD SUM 题目描述 for i=1 to n for j=1 to n sum+=gcd(i,j) 给出n求sum. gcd(x,y)表示x,y的最大公约数. 输入输出格式 输入 ...
- Filter 介绍
Filter 可认为是 Servlet 的一种加强版,它主要用于对用户请求进行预处理,也可以对 HttpServletResponse 进行后处理,是个典型的处理链. Filter 也可对用户请求生成 ...
- C++内存分配与释放
C++内存分配与释放 1. new 运算符 与 operator new一条 new 表达式语句( new Type; )中的 new 是指 new 运算符.operator new 是定义在 #in ...
- ECONNRESET和WSAECONNRESET怎么产生的以及如何避免
ECONNRESET是linux环境网络编程产生的错误,错误码为104, WSAECONNRESET是windows环境网络编程产生的错误,错误码为10054 两者产生的原因都一样,分以下几种情况: ...
- google的几道面试题
Question1:如何判断两个矩形是否有重叠区域? Answer(java): public boolean checkCross(Rectangle m, Rectangle n) { //求出m ...
- [DeeplearningAI笔记]序列模型3.1基本的 Seq2Seq /image to Seq
5.3序列模型与注意力机制 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.1基础模型 [1] Sutskever I, Vinyals O, Le Q V. Sequence to Se ...