Skip to content

Instantly share code, notes, and snippets.

@luckypapa
Created August 23, 2015 06:03
Show Gist options
  • Save luckypapa/4b3bc9aaad18659c3064 to your computer and use it in GitHub Desktop.
Save luckypapa/4b3bc9aaad18659c3064 to your computer and use it in GitHub Desktop.
//https://www.acmicpc.net/problem/1004
#include <stdio.h>
#define SQUARE(X) (X)*(X)
typedef struct{
int x;
int y;
int r;
} D;
int getMinimumNum(D start, D end,
D *planet, int planetNum) {
int totalNum = 0;
for (int i = 0; i < planetNum; i++) {
bool startPosition =
SQUARE(planet[i].r) > SQUARE(start.x - planet[i].x) +
SQUARE(start.y - planet[i].y);
bool endPosition =
SQUARE(planet[i].r) > SQUARE(end.x - planet[i].x) +
SQUARE(end.y - planet[i].y);
if (startPosition && !endPosition) {
totalNum++;
} else if (!startPosition && endPosition) {
totalNum++;
}
}
return totalNum;
}
int main(void) {
int T;
scanf("%d", &T);
while(T-- > 0) {
D start, end;
D planet[50] = { 0 };
int planetNum = 0;
scanf("%d %d %d %d", &start.x, &start.y, &end.x, &end.y);
scanf("%d", &planetNum);
for (int i = 0; i < planetNum; i++) {
scanf("%d %d %d", &planet[i].x, &planet[i].y, &planet[i].r);
}
printf("%d\n", getMinimumNum(start, end, planet, planetNum));
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment