Circles on a Screen | 프로그래밍의 벗 PivotOJ
PivotOJ

Circles on a Screen

시간 제한: 3000ms메모리 제한: 256MB출처: NEERC Northern Subregional 2009BOJ 3552
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Yesterday Andrew wrote a program that draws nn white circles on a black screen. The screen is monochrome and it has a resolution w×hw \times h pixels. Pixels are numbered from upper left corner (0,0)(0, 0) to bottom right one (w1,h1)(w-1, h-1).

A circle with the center at pixel (xc,yc)(x_c, y_c) and the radius rr consists of the pixels with coordinates (x,y)(x, y) such that (xcx)2+(ycy)2r\sqrt{(x_c - x)^2 + (y_c - y)^2} \le r. If the circle does not fit on the screen, it is truncated. If some pixel belongs to two or more circles, it is white.

[이미지 1]

The resulting picture was very nice, so Andrew decided to copy it to his wall. He has white wallpaper and he can only draw some parts of wall into black. Now he wants to know the amount of paint he needs. He copies the picture exactly pixel-to-pixel, so you should write a program that calculates the number of black pixels left on a screen after drawing nn circles.

입력

In the first line of input file there are three integers: ww, hh, and nn (1w,h200001 \le w, h \le 20\,000; 1n1001 \le n \le 100). Each of the following nn lines contains descriptions of the circle. In i+1i+1-th line there are three integers: xix_i, yiy_i, rir_i (0xi<w0 \le x_i < w; 0yi<h0 \le y_i < h; 0ri400000 \le r_i \le 40\,000). They denote a circle with the center at pixel (xi,yi)(x_i, y_i) and radius rir_i.

출력

You should output exactly one number --- the number of black pixels left on the screen.

힌트

The picture corresponds to the second example.

예제

예제 1

입력
5 3 2
1 1 1
3 1 1
출력
6

예제 2

입력
12 9 2
3 3 2
7 5 4
출력
51
코드를 제출하려면 로그인하세요.