Click Here to go back to the homepage.

Hitting the Targets Solution:


#include <bits/stdc++.h>

using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    vector<array<int, 4>> targets;
    int n_targets;
    cin >> n_targets;
    string type;
    while(n_targets--){
        cin >> type;
        array<int, 4> vals;
        if(type == "rectangle"){
            cin >> vals[0] >> vals[2] >> vals[1] >> vals[3];
        } else {
            cin >> vals[0] >> vals[1] >> vals[2];
            vals[2] = vals[2] * vals[2];
            vals[3] = INT_MAX;
        }
        targets.push_back(vals);
    }
    int shots;
    cin >> shots;
    int x, y, count;
    while(shots--){
        count = 0;
        cin >> x >> y;
        for(auto iter:targets){
            if(iter[3] == INT_MAX){
                if((x - iter[0]) * (x - iter[0]) + (y - iter[1]) * (y - iter[1]) <= iter[2]){
                    count++;
                }
            } else {
                if(iter[0] <= x && iter[1] >= x && iter[2] <= y && iter[3] >= y){
                    count++;
                }
            }
        }
        cout << count << endl;
    }

    return 0;
}