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[ ...
随机推荐
- webapp设计注意事项
色彩设计 美学相关的知识(色彩构成.平面构成等等)我就不再赘述了,相信从事此类行业的人员无人不知无人不晓了.这里简要说说WebApp设计中,色彩以及构图的特别之处吧. 首先是色彩.从事过广告和印刷业设 ...
- 【HDU2120】Ice_cream's world I(并查集基础题)
查环操作,裸题.一次AC. #include <iostream> #include <cstring> #include <cstdlib> #include & ...
- softlayer virtual machine vhd磁盘镜像导入shell脚本
脚本
- Rhythmbox中文乱码解决的方法
转自:http://hi.baidu.com/morgensonne/item/3470aef58747abde6325d2d9 今天在网络上找到了一个比較好的解决Rhythmbox中文乱码的问题的方 ...
- 批量创建prefab
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.IO; using UnityEdito ...
- 关于VS2008中的targetver.h文件
targerver.h文件的作用: 定义程序运行的环境,如限制程序只能在XP下运行,限制程序在只能在Vin7下运行 或限制程序只能在XP以上系统运行,或限制程序只能在Server2003以上系统运行. ...
- Flashback Recovery Area的设置与取消
在Oracle 10g中, Flash back家族分为以下成员: Flashback Database, Flashback Drop,Flashback Query(分Flashback Quer ...
- C#邮件发送
public static void CreateCopyMessage() { MailAddress from = new MailAddress("yang@163.com" ...
- Func 委托 和 Action 委托 初步谈论
继上篇EventHandler之后,继续填坑,简单了解下Func<TResult> 委托 和 Action 委托. msdn对于两者的解释: Func<TResult>:封装一 ...
- asp.net 读取Excel文档
<注:>默认读取数据从Excel的第二行开始. public DataSet ReadExcel(string Path) { string strConn = "Provide ...