题目来源:http://poj.org/problem?id=1031

题目大意:

  有一个光源位于(0,0)处,一个多边形的围墙。围墙是“全黑”的,不透光也不反射光。距光源r处的光强度为I0=k/r,k为常数。

  一块无穷窄高为h的墙上围墙受到的照度为dI=I0*|cosα|*dl*h,其中I0为该点光强,α为法线与该点到光源连线的夹角。

求总照度。(dI之和)

输入:第一行三个数,第一个数为给定的常数k,第二个数位围墙高h,第三个数为围墙顶点数。接下来每行为一个围墙的顶点,按遍历多边形的顺序给出。

输出:总的照度。


Sample Input

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

Sample Output

5.34

如果有一点点计算机视觉的基础或者物理直觉好的话,会知道结果实际与距离和夹角都没有关系,只要求光源向360°辐射的范围内,有多大的角度被墙挡住了。于是转化为了求围墙相对于光源张角的问题。

求张角的过程大致如下:

遍历所有的边,求边相对于光源的张角(自行规定一个正方向)。记录下每次求和之后的最大值和最小值(即像一个方向延扫得最远时的角度),但要注意不应该大于360度。

 //////////////////////////////////////////////////////////////////////////
// POJ1031 Fence
// Memory: 280K Time: 47MS
// Language: C++ Result: Accepted
////////////////////////////////////////////////////////////////////////// #include <iostream>
#include <math.h> #define M_PI 3.14159265 using namespace std; double k,h,x[],y[];
double angle(double x0, double y0, double x1, double y1) {
double a=atan2(y0, x0);
double b=atan2(y1, x1);
if (b - a > M_PI) a += * M_PI;
if (a - b > M_PI) b += * M_PI;
return a-b;
} int main () {
int i,n;
cin >> k >> h >> n;
for (i=; i<n; i++) {
cin >> x[i] >> y[i];
}
x[n] = x[], y[n] = y[]; double min = , max = , sum = ; for(i = ; i < n; i++) {
double temp = angle(x[i], y[i], x[i + ], y[i + ]);
sum += temp;
if (sum < min) min = sum;
if (sum > max) max = sum;
if (max - min >= * M_PI) {
max = min + * M_PI;
break;
}
}
printf("%.2lf\n", k * h * (max - min));
system("pause");
return ;
}

POJ1031 Fence的更多相关文章

  1. [LeetCode] Paint Fence 粉刷篱笆

    There is a fence with n posts, each post can be painted with one of the k colors. You have to paint ...

  2. poj 3253 Fence Repair

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 42979   Accepted: 13999 De ...

  3. CF 484E - Sign on Fence

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  4. poj3253 Fence Repair

    http://poj.org/problem?id=3253 Farmer John wants to repair a small length of the fence around the pa ...

  5. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  6. Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树

    E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consi ...

  7. ACM Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  8. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  9. [LintCode] Paint Fence 粉刷篱笆

    There is a fence with n posts, each post can be painted with one of the k colors.You have to paint a ...

随机推荐

  1. Skype SILK vs. iLBC vs. Speex

    对比一下这三种VOIP语音算法的特点: 1 参数与特征 2 SILK性能 关于iLBC和Speex的性能可以参考以前写的文章. 3 关于VOIP一些观点(仅代表个人观点) 1)  Skype 辛苦三年 ...

  2. 倍增模板orz

    #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #i ...

  3. BZOJ1218:[HNOI2003]激光炸弹

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.lydsy.com/JudgeOnline/probl ...

  4. PAT1106(BFS)

    PAT 1106 思路 BFS用在tree上,这一个题里主要关注的是用vector去保存每一个节点所连接的子节点,当BFS 时,一旦发现该节点下面没有子节点,这一层一定是最短的路径,然后用当前的层数去 ...

  5. ss1

    首先,对系统来一次升级,以解决一些莫名其妙的依赖问题. sudo yum update 然后安装Python-pip. sudo yum -y install python-pip 注意,通过yum包 ...

  6. qtp重定义数组大小

    a dim arr1() ) a  dim arr() ReDim arr(a) arr arr ) arr For each i in arr     print arr(i) Next

  7. [hdu1712]ACboy needs your help分组背包

    题意:一共$m$天,$n$门课程,每门课程花费$i$天得到$j$的价值,求最后获得的最大价值 解题关键:分组背包练习,注意循环的顺序不能颠倒 伪代码: $for$ 所有的组$k$   $for{\rm ...

  8. Unity实现支持泛型的事件管理以减少使用object作为参数带来的频繁装拆箱

    如果不用C#自身的event关键字而是要自己实现一个可统一管理游戏中各种消息事件通知管理的系统模块EventManger时,通常都是把事件delegate的参数定义为object类型以适应所有的数据类 ...

  9. php学习笔记-变量的作用域

    这个东西很难理解,但很重要,我觉得非常容易出错. PHP中的变量按照作用域分为有两种,一种是global,一种是local. 函数内部声明的变量就叫local型变量,只能在函数内部被访问到.一句话,l ...

  10. xgene:疾病相关基因,耳聋,彩色,老年痴呆,帕金森

    神经元的传递:一个下游神经元,它接受其上游神经元的各个突触传过来的信号,然而,每个突触对该下游神经元的激活权重是不同的. 从神经网络的本质上说,当人连续.多次遭受失败的时候,大脑内就会释放大量的抑制性 ...