题目来源: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. 如何生成HLS协议的M3U8文件

    什么是HLS协议: HLS(Http Live Streaming)是由Apple公司定义的用于实时流传输的协议,HLS基于HTTP协议实现,传输内容包括两部分,一是M3U8描述文件,二是TS媒体文件 ...

  2. p2p视频点播系统开发案例――Myseelite

    项目地址:http://sourceforge.net/projects/myseelite/ 1. MySee公司倡导的开源项目,目前国内功能最强大的一个开源系统. 2. 一个直播(也支持轮播.点播 ...

  3. Uva10366

    模拟乱搞 要说算法的话...乱搞算法? #include<iostream> #include<cstring> #include<algorithm> #incl ...

  4. Qt Quick之TableView的使用

    本博只是简单的展示TableView的基本使用(TableView.style:TableViewStyle.headerDelegate.rowDelegate.itemDelegate.Table ...

  5. 【转】mysql查询当天所有数据sql语句

    mysql查询当天的所有信息: select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) a ...

  6. stm32与三菱PLC通信

    一.三菱PLC通讯概要   三菱PLC FX系列通信结构如下图所示: 三菱PLC FX系列的通信规格如下图所示: 三菱PLC FX系列一般有以下几种通信模块,以FX2N为例: FX2N-232-BD ...

  7. 共有11款Python 中文分词库开源软件

    件过滤: 排序: 收录时间 | 浏览数 Python 中文分词库 Yaha "哑哈"中文分词,更快或更准确,由你来定义.通过简单定制,让分词模块更适用于你的需求. "Ya ...

  8. web实现本地缓存的方法

    Cookie(或者Cookies) 指一般网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密). cookie一般通过http请求中在头部一起发送到服务器端.一条c ...

  9. .NET后台控制网页标签的ICO图标

    aspx文件的head属性中增加runat="server" 后台cs文件中: /// <summary> /// 客户端注册ICO图标 /// </summar ...

  10. 使用PM2管理nodejs进程分享

    摘要:pm2 是一个带有负载均衡功能的Node应用的进程管理器.本文主要介绍了详解使用PM2管理nodejs进程,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧,希望能帮助 ...