题干:

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 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.

Examples

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.

题目大意:

一张长方形桌子的四个顶点全部在整数点位置,桌子的四条边上每个整数点(x,y) (x,y都是整数)位置有一把椅子,代表有一个人,当使用加热器在桌子周围加热时,问有几个人不在加热范围之内。

输入时每组数据首先给出两个点的坐标,代表一张桌子的对角线的端点,桌子的边与坐标轴平行,然后输入一个n,代表有n个加热器,接下来n行每行输入三个数x,y,r,代表这个加热器的坐标和加热半径。

解题报告:

刚开始还以为是在整个矩形内部都有点,但是看了样例发现是在矩阵的边上、、、所以要结合样例理解题目啊

一个加热器可以确定一个圆,判断每个人是否在圆内或圆上;输出不在圆内或圆上的人的个数即可。遍历这个矩形的边长跑一边就好了,时间复杂度O(4*n^2)大概。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int x1,x2,y1,y2;
int n,ans;
int x[1005],y[1005],r[1005];
int main()
{cin>>x1>>y1>>x2>>y2;//x1,y1,左下 cin>>n;for(int i = 1; i<=n; i++) {scanf("%d%d%d",x+i,y+i,r+i);}if(x1 > x2) swap(x1,x2);if(y1 > y2) swap(y1,y2);int j=y1;for(int i = x1; i<=x2; i++) {for(int k = 1; k<=n; k++) {if((i-x[k])*(i-x[k]) + (j-y[k])*(j-y[k]) <= r[k]*r[k]) {ans++;break;}}}j=y2;for(int i = x1; i<=x2; i++) {for(int k = 1; k<=n; k++) {if((i-x[k])*(i-x[k]) + (j-y[k])*(j-y[k]) <= r[k]*r[k]) {ans++;break;}}}  j = x1;for(int i = y1 + 1; i<=y2-1; i++) {for(int k = 1; k<=n; k++) {if((i-y[k])*(i-y[k]) + (j-x[k])*(j-x[k]) <= r[k]*r[k]) {ans++;break;}}}j = x2;for(int i = y1 + 1; i<=y2-1; i++) {for(int k = 1; k<=n; k++) {if((i-y[k])*(i-y[k]) + (j-x[k])*(j-x[k]) <= r[k]*r[k]) {ans++;break;}}}
//  cout << ans << endl;printf("%d\n", (x2-x1+1)*2 + (y2-y1-1)*2 - ans);return 0 ;
}

【CodeForces - 144B 】Meeting (暴力枚举,水题,计算几何)相关推荐

  1. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  2. [蓝桥杯2015决赛]分机号-枚举(水题)

    题目描述 X老板脾气古怪,他们公司的电话分机号都是3位数,老板规定,所有号码必须是降序排列,且不能有重复的数位. 比如:751,520,321 都满足要求,而766,918,201 就不符合要求. 现 ...

  3. [蓝桥杯][2013年第四届真题]核桃的数量-枚举(水题)

    题目描述 小张是软件项目经理,他带领3个开发组.工期紧,今天都在加班呢.为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑).他的要求是: 各组的核桃数量必须相同 各组内必须能平分核桃(当然是不能打 ...

  4. [蓝桥杯2015决赛]积分之迷-枚举(水题)

    题目描述 小明开了个网上商店,卖风铃.共有3个品牌:A,B,C. 为了促销,每件商品都会返固定的积分. 小明开业第一天收到了三笔订单: 第一笔:3个A + 7个B + 1个C,共返积分:315 第二笔 ...

  5. 【CodeForces - 569B】Inventory (水题)

    题干: Companies always have a lot of equipment, furniture and other things. All of them should be trac ...

  6. codeforces 702A A. Maximum Increase(水题)

    题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. 【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

    题干: Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degene ...

  8. CodeForces 444C. DZY Loves Physics(枚举+水题)

    转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...

  9. Codeforces gym 100685 C. Cinderella 水题

    C. Cinderella Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/ ...

  10. codeforces 667A A. Pouring Rain(水题)

    题目链接: A. Pouring Rain time limit per test 1 second memory limit per test 256 megabytes input standar ...

最新文章

  1. OpenGL--- 坐标系变换
  2. Openfire 的安装和配置
  3. Caffe中的损失函数解析
  4. 将格式化的日期字符串转换为Unix时间戳(php)
  5. 面向对象的特点封装、继承、多态
  6. remote addr 取到内网ip_内网穿透工具frp
  7. resharper 6.0 注册码
  8. Android 开发笔记 ProgressDialog的Back健关闭
  9. ReiBoot Pro for Mac(iOS系统修复软件)
  10. shell脚本学习指南_学习笔记_第1,2章
  11. 制作自己的绿色版 FireFox
  12. hdu 4517 小小明系列故事——游戏的烦恼(统计类题目)
  13. ZOJ3987(二进制枚举+java大数)
  14. Excel 多级下拉菜单设置,数据有效性
  15. C#中如何隐藏滚动条(ScrollBar)同时又具备自动滚动的功能
  16. WCF医院管理系统技术解析(十)体检报告结果打印(水晶报表)
  17. android 本地地址转换为url,安卓 File和url之间的转换
  18. 【PS-海报】地产海报学习笔记
  19. Linux之curl 风骚用法
  20. 博士申请 | 美国圣路易斯华盛顿大学王晨光老师招收NLP方向全奖博士/博后/硕士...

热门文章

  1. [Android]安装 Android Studio 第一行Android代码
  2. java 数据库连接池 开源_开源自己开发的一个JAVA数据库连接池,效果还算可以。...
  3. GOOGLE HACKING 系列文章 【FreeXploiT整理收集】
  4. php给留言分配id_简单实现PHP留言板功能
  5. threejs相机和渲染器
  6. python实现图形旋转_Python3+OpenCV2实现图像的几何变换
  7. asterisk1.8启动信息分析(未完)
  8. HTTP代理原理以及HTTP隧道技术
  9. 一个数据包大小是多少k_算法交流: 6046 数据包的调度机制 【2.6基本算法之动态规划】...
  10. linux c 内存elf,gcc加入linux ELF有什么功能?