我是靠谱客的博主 懦弱鱼,最近开发中收集的这篇文章主要介绍Codeforce 144B-Meeting 数学题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

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

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

解题思路:一个加热器可以确定一个圆,判断每个人是否在圆内或圆上;输出不在圆内或圆上的人的个数即可。

#include<stdio.h>
#include<string.h>
int n,i,j,t,cnt,sum,x1,x2,y1,y2;
struct radiator
{
int x;
int y;
int r;
}a[1005];
void dis(int X,int Y) /*判断是否在圆内或圆上*/
{
sum++; /*记录桌子周围的总人数*/
for(t=0;t<n;t++)
if((X-a[t].x)*(X-a[t].x)+(Y-a[t].y)*(Y-a[t].y)<=a[t].r*a[t].r)
{
cnt++;
/*记录在圆内或圆上的人的个数*/
break;
}
}
void cal1(int m,int p,int q)
/**/
{
for(i=m,j=p;i<=q;i++)
dis(i,j);
}
void cal2(int m,int p,int q) /**/
{
for(j=m,i=p;j<=q;j++)
dis(i,j);
}
int main()
{
int temp1,temp2;
while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2))
{
if(x1>x2)
{
temp1=x1;x1=x2;x2=temp1;
temp2=y1;y1=y2;y2=temp2;
}
/*保证x1<x2*/
sum=0;
cnt=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);
cal1(x1,y1,x2); /*和x轴平行的边上的点*/
cal1(x1,y2,x2); /*和x轴平行的边上的点*/
if(y1>y2)
{
cal2(y2+1,x1,y1-1); /*和y轴平行的边上的点*/
cal2(y2+1,x2,y1-1); /*和y轴平行的边上的点*/
}
else
{
cal2(y1+1,x1,y2-1); /*和y轴平行的边上的点*/
cal2(y1+1,x2,y2-1); /*和y轴平行的边上的点*/
}
printf("%dn",sum-cnt);
}
return 0;
}


最后

以上就是懦弱鱼为你收集整理的Codeforce 144B-Meeting 数学题的全部内容,希望文章能够帮你解决Codeforce 144B-Meeting 数学题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部