poj1031-Fence-acm解题报告

原题描述:

        

Fence
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3658 Accepted: 1261

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: 
I 0=k/r

where 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=I 0*|cosα|*dl*h

where I 0 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
 
//cpp
//poj1030-Fence
#include<stdio.h>  
#include<string.h>  
#include<algorithm>  
#include<math.h>  
#include<queue>  
#define dist(a,b) sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))  
#define cross(a,b,c) (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)  
#define dot(a,b,c) (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y)  
#define delt(a) fabs(a)<eps?0:a>0?1:-1  
#define pi acos(-1.0)  
#define eps 1e-8  
#define inf 1e20  
#define N 1005  
using namespace std;  
int n,m,t,nl,ml;  
struct TPoint  
{  
    double x,y;  
}pt[N],st;  
void scan()  
{  
    scanf("%lf%lf%d",&st.x,&st.y,&n);  
    for(int i=0;i<n;i++) scanf("%lf%lf",&pt[i].x,&pt[i].y);  
}  
double getang(TPoint a,TPoint b)  
{  
    double ang1=atan2(a.y,a.x),ang2=atan2(b.y,b.x);  
    if(ang1-ang2>pi) ang2+=2*pi;  
    if(ang2-ang1>pi) ang1+=2*pi;  
    return ang1-ang2;  
}  
void solve()  
{  
    double minf=0,maxf=0,sumf=0;  
    pt[n]=pt[0];  
    for(int i=0;i<n;i++)  
    {  
        sumf+=getang(pt[i],pt[i+1]);  
        maxf=max(sumf,maxf);  
        minf=min(sumf,minf);  
        if(maxf-minf>2*pi)  
        {  
            maxf=minf+2*pi; break;  
        }  
    }  
    printf("%.2f\n",(maxf-minf)*st.x*st.y);  
}  
int main()  
{  
    scan();  
    solve();  
    return 0;  
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值