Skip to content

Instantly share code, notes, and snippets.

@eddietree
Created December 12, 2014 20:30
Show Gist options
  • Save eddietree/3beb28bfcb679c4994c5 to your computer and use it in GitHub Desktop.
Save eddietree/3beb28bfcb679c4994c5 to your computer and use it in GitHub Desktop.
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdint>
using namespace std;
struct ArrowData
{
int x0, y0;
int x1, y1;
};
struct CircleData
{
int radius;
};
int main() {
int num_circles;
int num_arrows;
vector<ArrowData> arrows;
vector<CircleData> circles;
// grab circles
cin >> num_circles;
circles.resize(num_circles);
for( int i = 0; i < num_circles; ++i )
{
CircleData &data = circles[i];
cin >> data.radius;
}
// grab arrows
cin >> num_arrows;
arrows.resize(num_arrows);
for( int i = 0; i < num_arrows; ++i )
{
ArrowData &arrow_data = arrows[i];
cin >> arrow_data.x0 >> arrow_data.y0 >> arrow_data.x1 >> arrow_data.y1;
}
// count number of Qs
int count = 0;
for ( size_t i_arrow = 0; i_arrow < arrows.size(); ++i_arrow )
{
const ArrowData arrow = arrows[i_arrow];
const float arrow_dist_0 = sqrtf( float( arrow.x0 * arrow.x0 + arrow.y0 * arrow.y0 ) );
const float arrow_dist_1 = sqrtf( float( arrow.x1 * arrow.x1 + arrow.y1 * arrow.y1 ) );
for ( size_t i_circle = 0; i_circle < circles.size(); ++i_circle )
{
const CircleData circle = circles[i_circle];
const bool is_outside_0 = arrow_dist_0 > float(circle.radius);
const bool is_outside_1 = arrow_dist_1 > float(circle.radius);
// counts if one is inside and one is outside
count += (is_outside_0 != is_outside_1) ? 1 : 0;
}
}
cout << count;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment