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 ...
随机推荐
- CodeForces Gym 100228 Graph of Inversions
题目大意 对于一个长为$N$的序列$A$,定义它所对应的逆序图: 有$N$个点组成,标号为$1...N$的无向图,对于每一组$i,j(i<j)$若存在$A_i>A_j$则在新图中就存在一条 ...
- ElasticSearch logo 分布式搜索引擎 ElasticSearch
原文来自:http://www.oschina.net/p/elasticsearch Elastic Search 是一个基于Lucene构建的开源,分布式,RESTful搜索引擎.设计用于云计算中 ...
- nefu阶乘定理
Description 小明的爸爸从外面旅游回来给她带来了一个礼物,小明高兴地跑回自己的房间,拆开一看是一个很大棋盘(非常大),小明有所失望.不过没过几天发现了大棋盘的好玩之处.从起点(0,0)走到终 ...
- app专项测试(稳定性测试、安全性测试)
https://blog.csdn.net/xiaomaoxiao336368/article/details/84887948
- java用write()拷贝一个文本文件
总结:灵活运用循环语句,或条件判断语句.每一种流的正确使用方法: 这里是两种方法: package com.ds; import java.io.*; public class tyut { /*pu ...
- strdup与strndup
strdup()函数是c语言中常用的一种字符串拷贝库函数,一般和free()函数成对出现. extern char *strdup(char *s); 头文件:string.h 功 能: 将串拷贝到新 ...
- php-fpm包的安装与配置
实验环境:CentOS7 [root@~ localhost]#yum -y install php-fpm php-fpm包:用于将php运行于fpm模式 #在安装php-fpm时,一般同时安装如下 ...
- 调试opencv调用摄像头程序时碰到的问题
昨天晚上想把opencv学习笔记整理一下,当跑opencv调用摄像头的程序的时候老是出现Assertion failed (size.width>0 && size.height ...
- shell 自动删除n天前备份
Linux自动删除n天前备份Linux是一个很能自动产生文件的系统,日志.邮件.备份等.因此需要设置让系统定时清理一些不需要的文件.语句写法: find 对应目录 -mtime +天数 -na ...
- 树莓派 Learning 001 装机 ---之 1 安装NOOBS系统
树莓派安装NOOBS系统 (使用的树莓派板卡型号:Raspberry Pi 2 Model B V1.1)(板卡的型号在板子正面的丝印层上印着,你可以看到.) RASPBERRY PI 2 MODEL ...