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

题干:

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 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441484.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html中超链接使用_干货 | HTML中表格的使用方法

HTML中的表格是由表格的标签组成HTML中的表格是由标签用于定义表格的列&#xff0c;标签为又是标签来分割列&#xff0c;形成一个完整的表格。表格的标签组合关系为&#xff1a;我是单元格1我是单元格2表格中可以插入文本、图片、列表、段落、表单、水平线等任何html标签&#…

chrome插件中调用ajax,Chrome扩展程序中的Ajax调用无效

尝试在Chrome扩展程序中发送ajax请求。我已经确认请求返回200响应&#xff0c;它应该只是console.log来测试&#xff06;&#xff03;39;。我不确定这里是否存在异常问题&#xff1f;我已经阅读了Chrome扩展程序&#xff06;&#xff03;39; addListener&#xff06;&#xff0…

【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

题干&#xff1a; A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "…

互补品的交叉弹性系数_重庆事业单位综合备考:需求价格弹性和需求交叉价格弹性有何区别...

需求价格弹性 VS 需求交叉价格弹性一、需求价格弹性指某种商品随着价格的变化&#xff0c;该商品需求变化的程度大小(这里指的是同一种商品)。或者说&#xff0c;是需求变化相对于价格变化的敏感程度。假设&#xff1a;黄金、IPONE手机等商品降价50%&#xff0c;一定会大卖&…

esxi服务器与虚拟机时间不符,vsphere6.7-虚拟机与ESXI时间同步

ELF Format 笔记(十五)—— 符号哈希表ilocker:关注 Android 安全(新手) QQ: 2597294287 符号哈希表用于支援符号表的访问,能够提高符号搜索速度. 下表用于解释该哈希表的组织,但该格式并不属于 ELF 规范. ...AD域修改组策略如果我们的计算机加入AD域之后,修改安全策略时不能用…

朋友圈自动回复评论_微信新版,朋友圈可以表情包回复了!网友:评论区斗起来.jpg...

你们发现了吗&#xff1f;朋友圈可以发表情包评论了&#xff01;微信iOS版7.0.9正式版今天迎来更新支持发消息时可以引用之前的内容更令人惊喜的是不少网友都发现新版本还新增朋友圈自定义表情评论功能可以用表情包评论别人的朋友圈内容了&#xff01;轻触表情包还可以查看大图…

【CodeForces - 144D】Missile Silos(单源最短路,枚举中间边,枚举情况可能性)

题干&#xff1a; A country called Berland consists of n cities, numbered with integer numbers from 1to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. Accordi…

第九大陆服务器未找到文件,第九大陆服务器优化规则说明 拍卖行和寄售功能关闭公告...

第九大陆已经确定了六月份服务器的优化时间与规则&#xff0c;同时为了配合6月8日的服务器优化实施&#xff0c;拍卖行将于6月5日关闭&#xff0c;待服务器优化完成后即可开放&#xff01;给大家带来的不便&#xff0c;敬请您谅解&#xff01;《第九大陆》服务器优化详细规则说…

【牛客 - 210A】游戏(思维,脑洞)

题干&#xff1a; BLUESKY007,fengxunling和dreagonm三个人发现了一个像素游戏,这款神奇的游戏每次会生成一个nxm的网格,其中每一个格子都被随机染色为R,G,B三种颜色之一,每次都可以选择任意一个非B颜色的格子进行一次操作,每次操作都会满足以下规则&#xff1a; 1.操作的范围为…

建房子 最安全图纸_妄想山海初期该怎么办?砍树狩猎建房子,还能拆别人的房子...

妄想山海还是一个很有趣的游戏&#xff0c;唯一的缺点就是游戏对手机配置要求比较高&#xff0c;手机太差的玩家&#xff0c;就别想那么多了&#xff0c;希望等游戏正式上线&#xff0c;能优化的好一些吧&#xff01;在测试中&#xff0c;玩家能体验到游戏中的各种玩法&#xf…

【POJ - 2226】Muddy Fields(匈牙利算法 或 网络流dinic,二分图匹配,最小点覆盖,矩阵中优秀的建图方式 )

题干&#xff1a; Rain has pummeled the cows field, a rectangular grid of R rows and C columns (1 < R < 50, 1 < C < 50). While good for the grass, the rain makes some patches of bare earth quite muddy. The cows, being meticulous grazers, dont w…

springboot的原生cache_springboot-shiro-redis-session-cache

1.配置mysql和redis redis的需要配置密码 原生jedis的使用相对于spring-data-redis更加灵活 所以本项目用原生jedis来直接作为缓存使用 具体使用方法请参看相关配置 特别注意如果mysql是5.7以上版本&#xff0c;请去掉sql_mode中的ONLY_FULL_GROUP_BY 本项目用户支持多角色多部…

【51Nod - 1272 】最大距离 (思维,排序sort的空间优化)

题干&#xff1a; 给出一个长度为N的整数数组A&#xff0c;对于每一个数组元素&#xff0c;如果他后面存在大于等于该元素的数&#xff0c;则这两个数可以组成一对。每个元素和自己也可以组成一对。例如&#xff1a;{5, 3, 6, 3, 4, 2}&#xff0c;可以组成11对&#xff0c;如…

javaweb在线问卷系统_2020 最新流行的Java Web报表工具比对

随着信息系统的高速发展&#xff0c;报表平台逐渐成为了信息系统当中最为核心和重要的功能模块。报表工具有助于将原始数据可视化显示&#xff0c;使决策者或者相关人员能够一览整体的数据趋势&#xff0c;完整的报表解决方案会提供多样的表格数据展示、数据可视化元素&#xf…

python 深copy_python中的深copy和浅copy

bytesPython bytes/strbytes 在Python3中作为一种单独的数据类型&#xff0c;不能拼接&#xff0c;不能拼接&#xff0c;不能拼接>>> €20.encode(utf-8)b\xe2\x82\xac20>>> b\xe2\x82\xac20.decode(utf-8)€20解码>>> b\xa420.decode(windows-1255…

【HDU - 4185】Oil Skimming (二分图,建图,匈牙利算法)

题干&#xff1a; Thanks to a certain "green" resources company, there is a new profitable industry of oil skimming. There are large slicks of crude oil floating in the Gulf of Mexico just waiting to be scooped up by enterprising oil barons. One …

python pandas read_csv 迭代器使用方法_pandas.read_csv参数详解(小结)

更多python教程请到友情连接&#xff1a; 菜鸟教程www.piaodoo.com人人影视www.sfkyty.com飞卢小说网www.591319.com韩剧网www.op-kg.com兴化论坛www.yimoge.cn星辰影院www.hhsos.netpandas.read_csv参数整理读取CSV(逗号分割)文件到DataFrame也支持文件的部分导入和选择迭代参…

【HDU - 2398 】Savings Account (水题模拟)

题干&#xff1a; Suppose you open a savings account with a certain initial balance. You will not make any withdrawals or further deposits for a number of years. The bank will compound your balance (add the annual interest) once a year, on the anniversary …

隧道凿岩机器人_隧道凿岩机器人的研制

隧道凿岩机器人的研制隧道、洞室开挖是现代交通、能源、采掘、建筑等大规模基本建设中的一项难度大、耗资耗时多、劳动条件差但又十分重要、十分关键的施工作业。早期的液压凿岩设备全都是由人工操作的液压凿岩钻车&#xff0c;其施工效率和施工精度完全取决于操作人员的熟练程…

【HDU - 1045】Fire Net (dfs 或二分图)

题干&#xff1a; Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings through which to …