poj 3277 Mountains
http://poj.org/problem?id=3227
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 2000
using namespace std; int n,h;
const double eps=1e-;
int cmp(double x)
{
if(fabs(x)<eps) return ;
if(x>) return ;
return -;
}
struct point
{
double x,y;
point() {}
point(double a,double b):x(a),y(b) {}
} p[maxn]; double sqr(double x)
{
return x*x;
} double dis(point a,point b)
{
return (sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)));
} double det(point a,point b,point c,point d)
{
return (b.x-a.x)*(d.y-c.y)-(b.y-a.y)*(d.x-c.x);
} bool segem(point a,point b,point c,point d,point &e)
{
double s1=det(a,b,a,c);
double s2=det(a,b,a,d);
e.x=(c.x*s2-d.x*s1)/(s2-s1);
e.y=(c.y*s2-d.y*s1)/(s2-s1);
return true;
} double kk(point a,point b)
{
return (b.y-a.y)/(b.x-a.x);
}
int main()
{
while(scanf("%d%d",&n,&h)!=EOF)
{
if(n==&&h==) break;
for(int i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
point res;
res.x=;
res.y=h;
double sum=;
sum+=dis(p[],p[]);
point key;
key=p[];
for(int i=; i<n; i++)
{
double k3=kk(res,p[i]);
double k1=kk(p[i],p[i-]);
double k2=kk(res,key);
if(k3-k2>eps)
{
if(k1-k2>=)
{
point e;
segem(res,key,p[i-],p[i],e);
sum+=dis(e,p[i]);
key=p[i];
}
}
}
printf("%.2lf\n",sum);
}
return ;
}
poj 3277 Mountains的更多相关文章
- 离散化+线段树 POJ 3277 City Horizon
POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...
- 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...
- poj 3277 City Horizon (线段树 扫描线 矩形面积并)
题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ...
- POJ 3277 线段树+扫描线
题意: 思路: 线段树求矩形面积的并...同 POJ 1151 //By SiriusRen #include <cstdio> #include <algorithm> us ...
- POJ 3277 City Horizon(扫描线+线段树)
题目链接 类似求面积并..2Y.. #include <cstdio> #include <cstring> #include <string> #include ...
- [POJ] 3277 .City Horizon(离散+线段树)
来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_z ...
- POJ 3277 City Horizon(叶子节点为[a,a+1)的线段树+离散化)
网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archiv ...
- POJ 3277 City Horizon
标题效果: 每间房子的长度给出阴影(在间隔代表)而高度,求阴影总面积. 解题思路:矩形面积并. 以下是代码: #include <set> #include <map> #in ...
- poj很好很有层次感(转)
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...
随机推荐
- Ubuntu输入密码之后,桌面闪一下黑屏,然后又返回到输入密码界面。但是其他账户可以登入
1)原因:主目录下的.Xauthority文件拥有者变成了root,从而以用户登陆的时候无法都取.Xauthority文件 说明:Xauthority,是startx脚本记录文件.Xserver启动时 ...
- Resizable 2th click not working
here's a simple solution. just destroy the resizable function, then rebuild it. try { $("#div& ...
- 【高级算法】模拟退火算法解决3SAT问题(C++实现)
转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46453761 ---------------------------------- ...
- Android Dialog AlertDialog
1.普通的对话框 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...
- 《火球——UML大战需求分析》(第1章 大话UML)——1.4 如何学好UML?
说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...
- vs连接mysql
1.打开vs2012在aspx中添加一个Grid view 控件,,. 2,选择新建数据源. 3,选择数据库. 4,选择新建连接. 5,更改成mysql连接. 6,这里的Server name 是你自 ...
- js 获取元素在页面上的偏移量的最佳方式
使用js制作效果时,我们常常要获取某个元素在页面上的偏移量(例如tip提示框功能).而获取偏移量可以直接获取相对于document的偏移量,也可以获取相对与视口的偏移量(viewpoint)加上页面滚 ...
- div中的内容居中
要使div中的内容居中显示,不仅div要设定“text-align:centr" ,内置对象要添加margin:auto;属性才能使其在firefox等其他浏览器中也能居中.
- 安装 SQL Server2008 安装程序规则支持提示“重新启动计算机”失败
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager 删除 PendingFileRenameOperations这个 ...
- Rolling cURL: PHP并发最佳实践
Rolling cURL: PHP并发最佳实践 在实际项目或者自己编写小工具(比如新闻聚合,商品价格监控,比价)的过程中, 通常需要从第3方网站或者API接口获取数据, 在需要处理1个URL队列时, ...