POJ1031 Fence
题目来源: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的更多相关文章
- [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 ...
- poj 3253 Fence Repair
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42979 Accepted: 13999 De ...
- CF 484E - Sign on Fence
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- poj3253 Fence Repair
http://poj.org/problem?id=3253 Farmer John wants to repair a small length of the fence around the pa ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- 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 ...
- ACM Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- [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 ...
随机推荐
- 流媒体直播服务器:Bull-Live-Server
Bull Live Server 简称 BLS ,旨在使用C++语言提供强大功能和高性能的流媒体直播服务器. 为何要写 BLS ? 1.simple rtmp server https://githu ...
- POJ1061 青蛙的约会 和 LOJ2721 「NOI2018」屠龙勇士
青蛙的约会 Language:Default 青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 133470 Accep ...
- rsync 端口更换(默认873)
一般使用默认端口的话, 在服务端的启动命令为: /usr/bin/rsync --address=192.168.1.23 --daemon 如果在客户端需要换另外的端口侦听, 则使用 /usr/bi ...
- 动态webService
using System; using System.Net; using System.IO; using System.CodeDom; using Microsoft.CSharp; using ...
- C#读写.ini文件
转载来源: http://blog.csdn.net/source0573/article/details/49668079 https://www.cnblogs.com/wang726zq/arc ...
- 【jQuery】slice()方法的使用
[jQuery]slice()方法的使用 slice()方法:从已有的数组中返回选定的元素. 语法: arrayObj.slice(start, end) ...
- js数组与 json 的区别
一,数组 1. 定义一维数组:var s1=new Array(); s1=[1,2,3,4]或者s1[0]=1,s1[1]=2,s1[3]=3,s1[4]=4; alert(s1[0]); 结果为1 ...
- 选择炸了(JIRA)的88个
作者:Martin Seibert SEIBERT MEDIA 首席执行官. 原文地址:http://seibert.biz/jirareasons 作者Martin Seibert 是德国互联网代理 ...
- 使用PM2管理nodejs进程分享
摘要:pm2 是一个带有负载均衡功能的Node应用的进程管理器.本文主要介绍了详解使用PM2管理nodejs进程,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧,希望能帮助 ...
- C++中对象的常引用
直接传递对象名 用对象名做函数参数时,在函数调用时将建立一个新的对象,它是形参对象的拷贝. ================下面给出一个直接传递对象名的例子程序1.1================= ...