time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel
to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits.
Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the number ri —
the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal tori,
than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points(x1, y1) and (x2, y2) is
Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place.
The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under
the table) or on the perimeter (directly under some general). Even in this case their radius does not change.
Input
The first input line contains coordinates of two opposite table corners xa, ya, xb, yb (xa ≠ xb, ya ≠ yb).
The second line contains integer n— the number of radiators (1 ≤ n ≤ 103).
Then n lines contain the heaters' coordinates as "xi yi ri",
the numbers are separated by spaces. All input data numbers are integers. The absolute value of all coordinates does not exceed 1000, 1 ≤ ri ≤ 1000.
Several radiators can be located at the same point.
Output
Print the only number — the number of blankets you should bring.
Sample test(s)input
2 5 4 233 1 25 3 11 3 2
output
4
input
5 2 6 326 2 26 5 3
output
0
Note
In the first sample the generals are sitting at points: (2, 2), (2, 3), (2, 4), (2, 5), (3, 2), (3, 5), (4, 2), (4, 3), (4, 4), (4, 5).
Among them, 4 generals are located outside the heating range. They are the generals at points: (2, 5), (3, 5), (4, 4), (4, 5).
In the second sample the generals are sitting at points: (5, 2), (5, 3), (6, 2), (6, 3).
All of them are located inside the heating range.
解題說明:題目的意思是一張長方形桌子的四個頂點全部在整數點位置,桌子的四條邊上每個整數點(x,y) (x,y都是整數)位置有一把椅子,代表有一個人,當使用加熱器在桌子周圍加熱時,問有幾個人不在加熱範圍之內。輸入時每組資料首先給出兩個點的座標,代表一張桌子的對角線的端點,桌子的邊與座標軸平行,然後輸入一個n,代表有n個加熱器,接下來n行每行輸入三個數x,y,r,代表這個加熱器的座標和加熱半徑。一個加熱器可以確定一個圓,判斷每個人是否在圓內或圓上;輸出不在圓內或圓上的人的個數即可。
#include <stdio.h>#include <stdlib.h>#include<math.h>#include<string.h>int main(){ int a,b,c,d,m,i,e[10000],f[10000],g[10000],t,j,k,count=0; scanf("%d%d%d%d",&a,&b,&c,&d); if(a<c) { t=a; a=c; c=t; } if(b<d) { t=b; b=d; d=t; } scanf("%d",&m); for(i=1;i<=m;i++){scanf("%d%d%d",&e[i],&f[i],&g[i]);} for(j=c;j<=a;j++) { for(k=d;k<=b;k++) { if(j<a&&j>c){ if(k!=b&&k!=d){continue; }}for(i=1;i<=m;i++){if((pow(e[i]-j,2)+pow(f[i]-k,2))<=g[i]*g[i]){ break;} else if(i==m) { count++; } } }} printf("%d\n",count); return 0;}