Codeforces Round #430 (Div. 2) B. Gleb And Pizza【几何】

在这款趣味算法挑战中,玩家需确定多少香肠完全落在披萨的脆皮区域。通过计算香肠中心到原点的距离,并结合香肠半径,判断其是否完全位于披萨脆皮上,即半径r-d与r之间的区域。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Gleb And Pizza

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.

The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xiyi).

Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.

Input

First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust.

Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105).

Each of next n lines contains three integer numbers xiyi and ri ( - 500 ≤ xi, yi ≤ 500, 0 ≤ ri ≤ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri — radius of i-th peace of sausage.

Output

Output the number of pieces of sausage that lay on the crust.

Examples

input

Copy

8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1

output

Copy

2

input

Copy

10 8
4
0 0 9
0 0 10
1 0 1
1 0 2

output

Copy

0

Note

Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.

 

 

题意:一个pizza, 以原点为圆心, 半径为r, r-d半径内的是没有脆皮的部分, r-d 到 r 范围是有脆皮部分, 香肠的圆心为(x, y),半径为sr, 问有多少个香肠完全在脆皮部分上

分析:

  • 可以通过香肠圆心计算出 香肠到原点的距离D,再借由香肠的半径sr

求 D-sr 和 D+sr 是否在 r-d到r的范围内, 是则该香肠在脆皮上

 

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	
	int r,d,n,x,y,rr;
	int sum=0;//sum没初始化wa了
	cin>>r>>d;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	 cin>>x>>y>>rr;
	 double ans=sqrt(x*x+y*y);
	 double l=ans-rr;
	 double lr=ans+rr;
	 if(l>=r-d&&lr<=r)
	 sum++;
    }
    cout<<sum<<endl;
	
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值