1dP에서 본 어린왕자 문제를 풀어보았다.
이해하고 있었던 문제라 어려움이 없었다.
#include <stdio.h>
#include <math.h>
int main()
{
int test_case;
int x1,x2,y1,y2;
int cnt = 0;
int cx, cy, r;
int ast;
double dist1, dist2;
scanf("%d", &test_case);
while(test_case--){
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
scanf("%d", &ast);
while (ast--) {
scanf("%d %d %d", &cx, &cy, &r);
dist1 = abs(x1-cx) + abs(y1-cy);
dist2 = abs(x2-cx) + abs(y2-cy);
if(dist1 <= r && dist2 <=r) continue;
else if(dist1 <= r) cnt++;
else if(dist2 <= r) cnt++;
}
printf("%d\n", cnt);
}
}
'알고이즘 > 문제를 막풀어' 카테고리의 다른 글
[boj] no.1475 room number (0) | 2017.12.23 |
---|---|
[boj]no.2292 벌집 (0) | 2017.12.07 |
[boj] no.1003 피보나치 (0) | 2017.12.01 |
[boj] no.1074 Z (2) (0) | 2017.11.30 |
[boj] no.2775 부녀회장이 될테야 (0) | 2017.11.29 |