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 ...
随机推荐
- SuppressWarnings的警告
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...
- X265编译中C2220错误的解决办法
x265编译过程中 C2220错误:根本原因是代码是英文代码页,而我们的操作系统中使用的是中文代码页: 解决办法1 逐个文件进行格式转换,我在ubuntu下用iconv命令试过,没成功: 解决办法2 ...
- XCode5/Apple LLVM 5.0下使用boost的方法
Because Apple changes the compiler to llvm only in XCode5, so there are some compatible problems wit ...
- 再探Java基础——String.format(String format, Object… args)的使用
最近看到类似这样的一些代码:String.format("参数%s不能为空", "birthday"); 以前还没用过这功能不知咐意思,后研究了一下,详细讲解如 ...
- JavaScript数组的学习
1数组的创建 var arr1 = new Array(); var arr2=[1,2,3]; 2数组常用的方法: push,pop,shift,unshift,splice,slice,sort, ...
- Underscore.js 常用类型判断以及一些有用的工具方法
1. 常用类型判断以及一些有用的工具方法 underscore.js 中一些 JavaScript 常用类型检查方法,以及一些工具类的判断方法. 首先我们先来谈一谈数组类型的判断.先贴出我自己封装好的 ...
- ListControl一细节处理
做VC ListControl的时候发现一个问题,右击菜单的时候,在没有列表数据的空白处也会出现菜单,这可够纠结的,于是用了点方法解决了,希望分享同样不爽的朋友们.代码如下: void CXXXDlg ...
- hdu 2211
题意: 中文题目,自己看.............. 递归调用.... 没什么难度,注意下long long就行........ AC代码: #include <iostream> #de ...
- 兼容IE与firefox火狐的回车事件(js与jquery)
javascript 兼容IE与firefox火狐的回车事件 复制代码代码如下: <script language="javascript"> function key ...
- HDU_2068_RPG错排
Problem Description 今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁.RPG给他机会让他猜猜,第一次猜:R ...