UCF Local Programming Contest 2013(Practice)H. In the Spotlight 计算几何

UCF Local Programming Contest 2013(Practice)H. In the Spotlight

原题地址:

https://nanti.jisuanke.com/t/43743

基本题意:

在笛卡尔坐标的x轴上放置了一系列聚光灯,给出每个聚光灯的位置,聚光灯的光强,和聚光灯照射范围和中轴线的夹角,然后给出一个位置坐标(x,y) 问该位置的总光强是多少。
光强的计算公式计为:聚光灯光强 / 离聚光灯距离 ^ 2

基本思路:

通过题意我们可以发现,主要难点在对于每个聚光灯如何确认位置坐标是否在该聚光灯照射范围内;
开始我本来想套板子直接判断点和聚光灯左右边界射线的位置关系,然后板子好像有问题 QAQ;
想了一下发现没那么麻烦我们发现要使点在聚光灯照射范围内,只要确保聚光灯和该点的连线的倾斜角大于聚光灯左边界的倾斜角,小于聚光灯右边界的倾斜角就行了。
当确定了每个能照射到位置坐标的聚光灯,直接算距离套公式就行了。

ps.注意在算倾角的时候使用atan2()函数

关于atan2()函数和atan()函数的区别可以见百度百科

参考代码:

#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f

inline double dis(pair<double,double> a,pair<double,double> b){
    return (a.first - b.first)*(a.first - b.first) + (a.second-b.second)* (a.second-b.second);
}
const int maxn = 110;
double x,y;
int n;
double a[maxn],b[maxn],c[maxn];
pair<double,double> o,temp;
signed main() {
    int t;
    cin >> t;
    for (int cas = 1; cas <= t; cas++) {
        cin >> x >> y >> n;
        o = make_pair(x, y);
        for (int i = 1; i <= n; i++) cin >> a[i];
        for (int i = 1; i <= n; i++) cin >> b[i];
        for (int i = 1; i <= n; i++) cin >> c[i];
        double ans = 0;
        for (int i = 1; i <= n; i++) {
            temp = make_pair(a[i], 0);
            double k1 = (90.0 - b[i]) / 180.0 * acos(-1.0);
            double k2 = (90.0 + b[i]) / 180.0 * acos(-1.0);
            double hu = atan2(o.second - temp.second,o.first - temp.first);
            if (hu >= k1 && hu <= k2) {
                ans += c[i] / dis(o, temp);
            }
        }
        printf("Scene #%d: Spotlight intensity on Stacie is %.3f\n", cas, ans);
        cout << endl;
    }
}
发布了23 篇原创文章 · 获赞 7 · 访问量 1744

猜你喜欢

转载自blog.csdn.net/weixin_44164153/article/details/104808320
今日推荐