poj 1031

题目

Fence
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3669 Accepted: 1267

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

题意分析



代码

Source Code

Problem: 1031 User: PaladinDu
Memory: 188K Time: 16MS
Language: C Result: Accepted
  • Source Code
    #include <stdio.h>
    #include <math.h>
    /*
     * 先看题目给的公式
     * 1.点的强度
     * I0=k/r
     * r 是墙上点与光源在投影面上的距离
     * 所以这是一个平面几何问题,h只是一个普通系数
     * 2.投影面法线方向的线的强度公式
     * dI=I0*|cosα|*dl*h
     * α是墙的法线与墙上点与光源的线的夹角
     *
     * 如上图 这个|cosα|*dl 把墙的长度转为了圆弧的长度
     * 而圆弧的长度dl2公式为r*α (α为圆弧的角度)
     * 综合一下
     * dI = k*h*dl2/r (dl为圆弧长)
     * sult = k*h*α (α为圆弧的角度)
     *
     * 最后综合一下,求的是墙遮挡的角度
     *
     * 这里要用到一个math的方法 atan2(x,y) (求得是点到原点与x轴的夹角,范围:0-2π)
    */
    #define __INT_PI__ 3.1415926535898
    
    double mfGetAngle(double x0, double y0,
                      double x1, double y1) {
        double a=atan2(y0, x0);
        double b=atan2(y1, x1);
        if(a-b>__INT_PI__)
        {
            b=b+2*__INT_PI__;
        }
        if(b-a>__INT_PI__)
        {
            a=a+2*__INT_PI__;
        }
        return b-a;
    }
    int main(void) {
        int i,n;
        double k,h,x[101],y[101],min=0,max=0,next=0;//next是最后一个点与光源的连线 与 第一个点与光源的线,的夹角
        scanf("%lf %lf %d",&k,&h,&n);
        for(i=0;i<n;++i)
        {
            scanf("%lf %lf",&x[i],&y[i]);
        }
        x[n]=x[0],y[n]=y[0];
        for(i = 0; i < n; ++i)
        {
            next+=mfGetAngle(x[i],y[i],x[i+1],y[i+1]);
            if(next<min)
            {
                min=next;
            }else if(next>max)
            {
                max=next;
            }
            if(max-min>=2*__INT_PI__)
            {
                printf("%.2lf\n",k*h*2*__INT_PI__);
                return 0;
            }
        }
        printf("%.2lf\n", k*h*(max - min));
        return 0;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值