ZOJ3414Trail Walk(计算几何)
Trail Walk
Time Limit: 2 Seconds Memory Limit: 65536 KB
FatMouse is busy organizing the coming trail walk. After the route for the trail walk has been determine, the next important task is to set the location of CPs(check point).
The route is composed by n line segments which only intersect on their endpoints. Set the starting point of the trail walk as origin, the coordinate of the endpoints are p1 p2 p3 ... pn, in the order of walking direction.
Now FatMouse wants to set m CPs on the route in such way that the walking distance between adjacent CPs are all equal. You can treat the starting point as the CP0 and the end as CPm+1.
Input
There are multiple test cases. The first line of each case contains two integer n, m(1 <= n, m <= 1000). Then n pairs of integer followed, giving the coordinate of pi.
Output
The first line of each case, output "Route case_number", Then m lines followed, the ith line contains "CPcase_num: (xi, yi)" where (xi, yi) represent the coordinate of the CPi. Always keep three number after the decimal point.
Sample Input
3 3
1 1
2 3
3 5
Sample Output
Route 1
CP1: (1.026, 1.051)
CP2: (1.684, 2.368)
CP3: (2.342, 3.684)
题意:比赛时看不懂。。。英语好烂。。。原点为起点(CP0),从起点出发走到终点(Pn),途径P1,p2,p3...pn,在这条路上要设置检查站。相邻的检查站之间距离要相等。原点是给出的第一个检查站位置。
难点:一开始用斜率公式dx,由于斜率k和斜边距离都是正值,所以dx永远是正值,可是dx会出现为负值的情况。并且也存在斜率不存在的情况。
所以改用相似三角形可以解决。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define maxm 400007
#define maxn 1000+5 using namespace std;
int n,m;
struct Node
{
double x;
double y;
};
Node node[maxn];
double a[maxm];
double dx[maxn];
double dy[maxn];
double dis[maxn];
int main()
{
int cnt=;
while(~scanf("%d%d",&n,&m))
{
double sum=;
node[].x=;
node[].y=;
a[]=;
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&node[i].x,&node[i].y);
dx[i]=node[i].x-node[i-].x;
dy[i]=node[i].y-node[i-].y;
dis[i]=sqrt((node[i].x-node[i-].x)*(node[i].x-node[i-].x)+(node[i].y-node[i-].y)*(node[i].y-node[i-].y));
sum+=dis[i];
dx[i]/=dis[i];
dy[i]/=dis[i];
a[i]=sum;
}
double d=sum/(m+);
double t=d;
printf("Route %d\n",++cnt);
int num=;
for(int i=;i<=m;i++)
{
for(int i=;i<=n;i++)
if(a[i-]<d&&d<=a[i])
{ double d1=d-a[i-];
double x1=d1*dx[i]+node[i-].x;
double y1=d1*dy[i]+node[i-].y;
printf("CP%d: (%.3lf, %.3lf)\n",++num,x1,y1);
d+=t;
break;
} } }
return ;
}
ZOJ3414Trail Walk(计算几何)的更多相关文章
- POJ 2031 Building a Space Station (计算几何+最小生成树)
题目: Description You are a member of the space station engineering team, and are assigned a task in t ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- python os.walk()
os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- LYDSY模拟赛day1 Walk
/* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- How Google TestsSoftware - Crawl, walk, run.
One of the key ways Google achievesgood results with fewer testers than many companies is that we ra ...
- poj[3093]Margaritas On River Walk
Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...
- os.walk()
os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. walk()方法语法格式如下: os.walk(top[, topdown=True[, onerror=None[ ...
随机推荐
- linux网络编程之TCP/IP基础
(一):TCP/IP协议栈与数据包封装 一.ISO/OSI参考模型 OSI(open system interconnection)开放系统互联模型是由ISO(International Organi ...
- 为项目编写Readme.MD文件
了解一个项目,恐怕首先都是通过其Readme文件了解信息.如果你以为Readme文件都是随便写写的那你就错了.github,oschina git gitcafe的代码托管平台上的项目的Readme. ...
- html5 视频
HTML规定了一种通过video元素来包含视频的标准方法 一段HTML5视频不可缺少的元素有video.controls等.. 直到现在,仍然不存在一项在网页上显示视频的标准. 大多数视频是通过fla ...
- 【转载】ADO.NET与ORM的比较(4):EntityFramework实现CRUD
[转载]ADO.NET与ORM的比较(4):EntityFramework实现CRUD 说明:个人感觉在Java领域大型开发都离不了ORM的身影,所谓的SSH就是Spring+Struts+Hiber ...
- ios开发中的基本设计模式
(一)代理模式应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现.优势:解耦合敏捷原则:开放-封闭原则实例:tableview的 数据源delegate,通过和protoc ...
- UI开发学习中遇到的问题汇总
1.给UIView设置圆角,边框,阴影绘制,需要使用layer 1)设置圆角cornerView.layer.cornerRadius = 20; //设置试图圆角的大小cornerView.laye ...
- hdu 1587
Problem Description As you know, Gardon trid hard for his love-letter, and now he's spending too muc ...
- I/O多路复用之epoll
1.select.poll的些许缺点 先回忆下select和poll的接口 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set ...
- xyiyy开始写博客了
拖延症一直到现在才开始写博客... 希望写的博客对大家能有一些帮助,有不恰当或者不对的地方,还望大家指出. 以下为我的两个昵称:fraud xyiyy
- 一个有趣的问题——MySQL中varchar的最大长度
明明维护了一个1k的最小堆,可是输出到MySQL里却只有九百多行数据. 查log,发现这么一段内容: stderr logs com.mysql.jdbc.MysqlDataTruncation: D ...