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. Linux2.6内核--VFS层中和进程相关的数据结构

          系统中的每一个进程都有自己的一组打开的文件,像根文件系统,当前工作目录,安装点等.有三个数据结构将 VFS 层和系统的进程紧密的联系在一起,它们分别是: file_struct,fs_st ...

  2. 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)

    欢迎"热爱编程"的高考少年--报考杭州电子科技大学计算机学院 Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memor ...

  3. 10 Powerful Apache Modules--reference

    Apache is the most popular web server in the world,because it is more efficient than others.Thrust o ...

  4. [转] 浅谈 C++ 中的 new/delete 和 new[]/delete[]

    转:http://www.cnblogs.com/hazir/p/new_and_delete.html 在 C++ 中,你也许经常使用 new 和 delete 来动态申请和释放内存,但你可曾想过以 ...

  5. csv操作帮助类

    功能描述: 集合转换为csv数据 DataSe转换为csv数据 using System; using System.Collections.Generic; using System.Data; u ...

  6. HDU -2674 N!Again(小技巧)

    这道题有个小技巧,就是既然是n!,那么对2009求余,只要大于2009!,那么一定是0,在仔细想想会发现,根本到不了2009,只要到2009的最大质因数就行了,为什么呢?因为最大质因数是最大的一个不能 ...

  7. spring02IOC

    1.创建所需要的Student 和 Grade实体类 public class Student { //学生实体类 private String name; //姓名 private Integer ...

  8. 简单水池&&迷宫问题

    #include <iostream> #include <stdio.h> #include <cstring> using namespace std; int ...

  9. css控制背景图片在浏览器中居中,下拉浏览器的时候背景图一直不变

    如 http://www.gm.com/ css样式如下 ;;} #con{ position:absolute; ; ; height:100%; width:100%; background-im ...

  10. 电厂MIS,SIS简介

    MIS(Management Information System)管理信息系统,主要指的是进行日常事务操作的系统,它使管理人员及时了解公司现状和各种消息,它是电力企业管理现代化的重要标志. 一个典型 ...