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 ...
随机推荐
- BZOJ1072 排列perm 【状压dp】
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能 被2整除,其中末位为2的有30种,末位为4的有60种. Inpu ...
- mysql数据库----python操作mysql ------pymysql和SQLAchemy
本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy 一.pymysql pymsql是Python中操作MySQL的模块,其使用方法和MySQ ...
- Linux下的tar压缩解压缩命令详解(转)
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...
- String的indexOf方法
indexOf(String.indexOf 方法)字符串的IndexOf()方法搜索在该字符串上是否出现了作为参数传递的字符串,如果找到字符串,则返回字符的起始位置 (0表示第一个字符,1表示第二个 ...
- duilib CDateTimeUI 在Xp下的bug修复
转自:http://my.oschina.net/u/343244/blog/370131 CDateTimeUI 的bug修复.修改CDateTimeWnd的HandleMessage方法 ? 1 ...
- form:select form:options 标签数据回显
在jsp页面中经常会使用到 form:select form:options 遍历后台List集合生成 select 下拉选择器,但是 form:options 标签并没有提供一个可以回显数据的属性. ...
- CF544 C 背包 DP
n个人写m行代码,第i人写一行代码有a[i]个bug,问总bug数不超过b的不同方案数. 其实就是个背包,dp[i][j][k]代表前i个人写了j行代码用了k个bug限度,然后随便转移一下就好了 /* ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- Spring Cacheable 注解不缓存null值
用Cacheable注解时,发现空值,也会被缓存下来.如果我们期望空值不被缓存,可以做如下设置: @Cacheable(key = "#id", unless="#res ...
- 强制换行CSS样式
语法: word-wrap : normal | break-word 取值: normal :? 默认值.允许内容顶开指定的容器边界 break-word :? 内容将在边界内换行.如果需要,词内换 ...