题目来源: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. 使用UIBezierPath添加投影效果

                             代码: ViewController.h #import <UIKit/UIKit.h> @interface ViewControlle ...

  2. [转]CSS3盒模型display:box详解

    时间:2014-02-25来源:网络作者:未知编辑:RGB display:box;box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典的一个布 ...

  3. UOJ #348 州区划分 —— 状压DP+子集卷积

    题目:http://uoj.ac/problem/348 一开始可以 3^n 子集DP,枚举一种状态的最后一个集合是什么来转移: 设 \( f[s] \) 表示 \( s \) 集合内的点都划分好了, ...

  4. 洛谷 P4220 & UOJ #347 通道 —— 随机化

    题目:https://www.luogu.org/problemnew/show/P4220 http://uoj.ac/problem/347 先写了一下 n^2 和三棵树一样的情况,n^2 还写了 ...

  5. 继承Application以实现全局资源共享

    原文地址:http://www.cnblogs.com/Dentist/p/Mr_Dentist_.html 每个程序运行时会创建一个Application类的对象且仅有一个.在app结束时这个App ...

  6. 块级&行内元素总结

    一.块级元素与行内元素的区别 块级元素与行内元素有几个关键区别: 格式 默认情况下: 块级元素会新起一行: 行内元素不会以新行开始. 内容模型 一般块级元素可以包含行内元素和其他块级元素.这种结构上的 ...

  7. Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)

    一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...

  8. 通过能别的主机连接yum库

    本地有两台主机,分别为:192.168.2.131/24和192.168.2.132/24,本地yum源只能连接互联网: 这两台设备的虚拟机配置如下: 现有一台主机:172.16.254.88/16可 ...

  9. hibernate 数据关联一对一

    第一种一对一 person和card,card的id即作为主键,又作为外键  // 各村对方的一个对象 public class Person { private Integer id; privat ...

  10. PhpStorm选中相同文字高亮

    1.Setting(设置)->plugins->Browse Repositories 输入BrowseWordAtCaret 搜索,安装,然后重启: 2.Setting(设置) -> ...