Fence
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3018   Accepted: 1010

Description

There is an area bounded by a fence on some flat field. The fence has the height h and in the plane projection it has a form of a closed polygonal line (without self-intersections), which is specified by Cartesian coordinates (Xi, Yi) of its N vertices. At the point with coordinates (0, 0) a lamp stands on the field. The lamp may be located either outside or inside the fence, but not on its side as it is shown in the following sample pictures (parts shown in a thin line are not illuminated by the lamp): The fence is perfectly black, i.e. it is neither reflecting, nor diffusing, nor letting the light through. Research and experiments showed that the following law expresses the intensity of light falling on an arbitrary illuminated point of this fence: I0=k/rwhere k is a known constant value not depending on the point in question, r is the distance between this point and the lamp in the plane projection. The illumination of an infinitesimal narrow vertical board with the width dl and the height h is dI=I0*|cosα|*dl*hwhere I0 is the intensity of light on that board of the fence, α is the angle in the plane projection between the normal to the side of the fence at this point and the direction to the lamp.  You are to write a program that will find the total illumination of the fence that is defined as the sum of illuminations of all its illuminated boards. 

Input

The first line of the input file contains the numbers k, h and N, separated by spaces. k and h are real constants. N (3 <= N <= 100) is the number of vertices of the fence. Then N lines follow, every line contains two real numbers Xi and Yi, separated by a space.

Output

Write to the output file the total illumination of the fence rounded to the second digit after the decimal point.

Sample Input

0.5 1.7 3
1.0 3.0
2.0 -1.0
-4.0 -1.0

Sample Output

5.34

题目大意:求一个用篱笆围成的多边形对灯泡发出的光单位时间吸收的能量,灯泡发出的光射到篱笆上不穿透,不反射,不衍射(即篱笆受到的光能全部吸收)。

光照强度公式:I0=k/r(I0光照强度,k固定系数,r光照点到光源的距离)

对于某一小段线段的光能量公式:dI=I0*|cosα|*dl*h(di单位时间吸收的光能,I0此处的光照强度,dl一小段篱笆的长度,h篱笆的高度,α光在这小段篱笆上的入射角的余角(设b为入射角,那么α=90-b))

设光源到这条边的距离为t:

dI=I0*|cosα|*dl*h     (cosα=t/r)

  =k/r*t/r*h*dl

  =h*k*t/(r*r)*dl

  =hkt/(t*t+l*l)*dl

l是自变量,hkt是定量,对1/(t*t+l*l)*dl积分。

根据定积分可求出这一条篱笆单位时间吸收的能量:

∫1/(t^2+l^2)dl

根据定积分公式:∫1/(a^2+x^2)dx=1/a*arctan(x/a)+c

得:∫1/(t^2+l^2)dl=1/t*arctan(l/t)+c

所以 ∫kht/(t^2+l^2)dl=kh*arctan(l/t)+c

tan(a)=l/t

接下来求原点光源发散出的光被边覆盖的总弧度和。 每条边都有它的起始极角跟终点极角,它们的角度差就为这条变覆盖光的弧度大小, 由于光不能穿透,所以有重叠的地方只能计算一遍,以x轴正方向为起始位置,光源周围的范围为(0-2*PI),每条边都有他的范围,接下来求区间覆盖就行了。 需要注意的地方:有些边穿过x正半轴这样不好处理,因此把这样的边以x正半轴切成两条边(使得每条边的起始极角都<=0,便于求区间覆盖问题)

真JB操蛋,多组案例输入就一直WA。

#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std; struct Point{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
}; struct Seg{
double s,e;
};
typedef Point Vector;
Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator /(Vector A,double p){return Vector(A.x/p,A.y/p);}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps=1e-10;
const double PI=acos(-1*1.0);
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
else return x<0?-1:1;
}
bool operator == (const Point &a,const Point &b){
return (dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0);
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量长度
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//两向量的夹角
double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
double angle(Point p){ return atan2(p.y,p.x);}
double DistanceToLine(Point P,Point A,Point B)//点到直线的距离
{
Vector v1=B-A,v2=P-A;
return fabs(Cross(v1,v2)) / Length(v1);
} Point read_point()
{
Point P;
scanf("%lf %lf",&P.x,&P.y);
return P;
} vector<Point> p;
vector<Seg> s; bool mycomp(const Seg &a,const Seg &b)
{
if(dcmp(a.s-b.s) != 0) return a.s<b.s;
else return a.e<b.e;
} void swap(double &a,double &b)
{
double t=a;
a=b;b=t;
} double GetAngle(Point a)
{
double ang=angle(a);
if(dcmp(ang) < 0) ang+=2*PI;
return ang;
} void SegmentDeal()
{
int i,j,n=p.size();
Seg s1,s2;
for(i=0;i<n;i++)
{
j=(i+1)%n;
s1.s=GetAngle(p[i]);s1.e=GetAngle(p[j]);
if(dcmp(s1.s-s1.e) > 0) swap(s1.s,s1.e);
if(dcmp(s1.e-s1.s-PI) > 0)
{
s2.s=0;s2.e=s1.s;
s1.s=s1.e;s1.e=2*PI;
s.push_back(s2);
}
s.push_back(s1);
}
sort(s.begin(),s.end(),mycomp);
}
double solve()
{
int i,n;
double L,R;
double ans=0;
SegmentDeal();
n=s.size();L=s[0].s;R=s[0].e;
for(i=1;i<n;i++)
{
if(dcmp(s[i].s-R) <= 0)
{
if(dcmp(s[i].e-R) > 0) R=s[i].e;
}
else
{
ans=R-L;
L=s[i].s;
R=s[i].e;
}
}
ans+=R-L;
return ans;
}

int main()
{
int n,i;
double h,k,ans;
scanf("%lf %lf %d",&k,&h,&n);
p.clear();s.clear();
for(i=0;i<n;i++) p.push_back(read_point());
ans=solve();
printf("%.2lf\n",ans*h*k);
return 0;
}
 

												

poj 1031 多边形对点(向周围发射光线)的覆盖的更多相关文章

  1. poj 3082多边形相交 'Roid Rage

    题意是判断多边形是否相交 主要的思路就是判断每一个点是否在另外的多变形内 判断一个点是否在另一个多边形内主要思路是: 判断的那个点向左边做射线,如果射线与多边形的交点为奇数个则在多边形内,偶数个则不在 ...

  2. 【高德地图API】从头德国高中生JS API(三)覆盖物——大喊|折线|多边形|信息表|聚合marker|点蚀图|照片覆盖

    覆盖物,是一张地图的灵魂.有覆盖物的地图.才是完整的地图.在一张地图上,除了底层的底图(瓦片图,矢量图),控件(有功能可操作的工具).最重要最必不可少的就是覆盖物了.覆盖物有多种.包含.标注.折线.多 ...

  3. poj 2594Treasure Exploration(有向图路径可相交的最小路径覆盖)

    1 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> ...

  4. Treasure Exploration POJ - 2594 【有向图路径可相交的最小路径覆盖】模板题

    Have you ever read any book about treasure exploration? Have you ever see any film about treasure ex ...

  5. POJ 1442 Air Raid(DAG图的最小路径覆盖)

    题意: 有一个城镇,它的所有街道都是单行(即有向)的,并且每条街道都是和两个路口相连.同时已知街道不会形成回路. 可以在任意一个路口放置一个伞兵,这个伞兵会顺着街道走,依次经过若干个路口. 问最少需要 ...

  6. opengl入门学习

    OpenGL入门学习 说起编程作图,大概还有很多人想起TC的#include <graphics.h>吧? 但是各位是否想过,那些画面绚丽的PC游戏是如何编写出来的?就靠TC那可怜的640 ...

  7. OpenGL入门学习(转)

    OpenGL入门学习 http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html 说起编程作图,大概还有很多人想起TC的#includ ...

  8. OpenGL---------光照的基本知识

    从生理学的角度上讲,眼睛之所以看见各种物体,是因为光线直接或间接的从它们那里到达了眼睛.人类对于光线强弱的变化的反应,比对于颜色变化的反应来得灵敏.因此对于人类而言,光线很大程度上表现了物体的立体感. ...

  9. OpenGL理解

    说起编程作图,大概还有很多人想起TC的#include <graphics.h>吧? 但是各位是否想过,那些画面绚丽的PC游戏是如何编写出来的?就靠TC那可怜的640*480分辨率.16色 ...

随机推荐

  1. hydra 中文文档

    hydra(九头蛇)是一款开源的协议爆破工具,功能十分强大!!! 具体使用如下: -R   继续从上一次进度接着破解 -I 忽略已破解的文件进行破解 -S 采用SSL链接 -s 端口 指定非默认服务端 ...

  2. 【转】CPU个数,核心数,线程数

    我们在买电脑的时候,经常会看cpu的参数,对cpu的描述有这几种:“双核”.“双核四线程”.“四核”.“四核四线程”.“四核8线程”……. 我们接触的电脑基本上都只有一个cup.cpu的个数很容易得到 ...

  3. linux 常用命令(持续更新)

    查看IP地址 ifconfig 查看TCP端口 netstat -ntlp vi 文本编辑 (1)进入vi编辑模式 在vi的默认模式中,直接在界面中输入: i 在光标所在位置开始编辑: a 在光标所在 ...

  4. MYSQL - 限制资源的使用

    MYSQL - 限制资源的使用 1.MAX_QUERIES_PER_HOUR 用来限制用户每小时运行的查询数量 mysql> grant select on *.* to 'cu_blog'@' ...

  5. ios之UISearchBar

    当你在seachBar中输入字母之前的时候,只是用鼠标选中searchBar的时候,如图 终端输出截图如下:(这个时候调用先shouldBeginEditing,之后调用didBeginEditing ...

  6. Windows平台下使用vs code搭建python3环境(1)

    前言:最近几周在使用python开发的过程中,碰到了好多坑,由于以前使用visual studio 2015习惯了,导致刚开始搭建python开发环境以及管理各种包的时候有点不习惯,再加上python ...

  7. [POJ]1164 The Castle

    //markdown复制进来一堆问题 还是链接方便点 POJ 1164 The Castle 首先想到用9个方格来表示一个房间,如此一来复杂许多,MLE代码如下: //Writer:GhostCai ...

  8. kvm虚拟迁移

    1. 虚拟迁移 迁移: 系统的迁移是指把源主机上的操作系统和应用程序移动到目的主机,并且能够在目的主机上正常运行.在没有虚拟机的时代,物理机之间的迁移依靠的是系统备份和恢复技术.在源主机上实时备份操作 ...

  9. LeetCode(39) Combination Sum

    题目 Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C w ...

  10. Web自动化Selenium2环境配置中Selenium IDE的安装

    下载的firefox32.0的版本,但是在附件组件中只有selenuim IDE button,本以为这个就是selenium IDE插件,自以为是的后果就是把自己坑了.并且像一些selenium I ...