Codeforces Round #103 (Div. 2)——B

B. Meeting
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 to ri, 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 xayaxbyb (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 10001 ≤ 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 2
3
3 1 2
5 3 1
1 3 2
output
4
input
5 2 6 3
2
6 2 2
6 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.

#include <iostream>
#include <cstdio>
#include <algorithm>
#define maxn 1005
using namespace std;

struct Node
{
    int x,y,r;
} node[maxn];

bool dis(int a,int b,int c,int d,int r)//判断点是否在范围内
{
    int l=(a-c)*(a-c)+(b-d)*(b-d);
    if(l<=r*r) return true;
    else return false;
}
int main()
{
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    int xmin=min(x1,x2),xmax=max(x1,x2);
    int ymin=min(y1,y2),ymax=max(y1,y2);
    int n;
    scanf("%d",&n);
    int i,j,k;
    for(i=0; i<n; i++)
        scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].r);
    int cnt=0,c=0;
    for(i=xmin; i<=xmax; i++)
        for(j=ymin; j<=ymax; j++)
        {
            if(i>xmin&&i<xmax&&j>ymin&&j<ymax) continue;//由于是桌子,只有边上有将军
            c++;//计算将军的总数
            for(k=0; k<n; k++)
                if(dis(i,j,node[k].x,node[k].y,node[k].r))
                {
                    cnt++;//计算在散热器范围内将军数量
                    break;
                }
        }
    printf("%d\n",c-cnt);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值