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

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

Original title address:

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

Basic questions:

A series of spotlights are placed on the x-axis of Cartesian coordinates, giving the position of each spotlight, the intensity of the spotlight, and the angle between the spotlight's irradiation range and the central axis, and then giving a position coordinate (x, y) What is the total light intensity at this location.
The formula for calculating the light intensity is: Spotlight intensity / distance from spotlight ^ 2

The basic idea:

Through the title we can find that the main difficulty is how to confirm whether the position coordinates of each spotlight are within the range of the spotlight; at
first I originally wanted to set the board to directly determine the positional relationship between the point and the left and right boundary rays of the spotlight, then the board seems to have a problem After
thinking about it, we found that it is not so troublesome. We found that to make the point within the range of the spotlight, as long as the inclination angle of the connection line between the spotlight and the point is greater than the inclination angle of the left border of the spotlight and less than the inclination angle of the right border of the spotlight.
When you have determined each spotlight that can illuminate the position coordinates, just calculate the distance formula directly.

ps. Note that the atan2 () function is used when calculating the inclination

For the difference between the atan2 () function and the atan () function, see Baidu Encyclopedia

Reference Code:

#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;
    }
}
Published 23 original articles · praised 7 · visits 1744

Guess you like

Origin blog.csdn.net/weixin_44164153/article/details/104808320