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的更多相关文章

  1. 离散化+线段树 POJ 3277 City Horizon

    POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...

  2. 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543

    学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...

  3. poj 3277 City Horizon (线段树 扫描线 矩形面积并)

    题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ...

  4. POJ 3277 线段树+扫描线

    题意: 思路: 线段树求矩形面积的并...同 POJ 1151 //By SiriusRen #include <cstdio> #include <algorithm> us ...

  5. POJ 3277 City Horizon(扫描线+线段树)

    题目链接 类似求面积并..2Y.. #include <cstdio> #include <cstring> #include <string> #include ...

  6. [POJ] 3277 .City Horizon(离散+线段树)

    来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_z ...

  7. POJ 3277 City Horizon(叶子节点为[a,a+1)的线段树+离散化)

    网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archiv ...

  8. POJ 3277 City Horizon

    标题效果: 每间房子的长度给出阴影(在间隔代表)而高度,求阴影总面积. 解题思路:矩形面积并. 以下是代码: #include <set> #include <map> #in ...

  9. poj很好很有层次感(转)

    OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...

随机推荐

  1. Exception in thread "main" com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag.

    webservice 抛异常,原因: public class HeaderHandler implements SOAPHandler<SOAPMessageContext>{ @Ove ...

  2. 基于wax的lua IOS插件开发

    作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf Objective-C的运行时支持新增类型和方法,但是由于 ...

  3. html5 教程

    http://www.tutorialspoint.com/html5/index.htm

  4. .NET页面301跳转处理

    //301跳转Response.Status = "301 Moved Permanently";Response.AddHeader("Location", ...

  5. 浅谈Manacher算法与扩展KMP之间的联系

    首先,在谈到Manacher算法之前,我们先来看一个小问题:给定一个字符串S,求该字符串的最长回文子串的长度.对于该问题的求解.网上解法颇多.时间复杂度也不尽同样,这里列述几种常见的解法. 解法一   ...

  6. [Unit Testing] Node testing: Test api Get request

    Using mocha: "devDependencies": { "should": "^5.2.0", "supertest& ...

  7. LOAD DATA INFILE Syntax--官方

    LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name' [REPLACE | IGNORE] INTO TABLE tbl_n ...

  8. 简单题思维转化BestCoder

    题意:给你a, b, c, d四个数,这几个数的范围都是大于0小于1000的整数,让比较 a ^b 和 c ^ d的大小. 这道题看着特别简单,但是当时就是做不出来,将近一个月没有做题了,手生了,不过 ...

  9. fork安全的gettid高效实现

    进程有id,可以通过getpid()获得,线程也有id,但是glibc没有提供封装.需要自己发出系统调用.在关键路径,系统调用还是对性能有影响的.因此我们可以想到类似glibc对getpid做的cac ...

  10. EventBus 事件总线 案例

    简介 地址:https://github.com/greenrobot/EventBus EventBus是一个[发布 / 订阅]的事件总线.简单点说,就是两人[约定]好怎么通信,一人发布消息,另外一 ...