Codeforces Round #430 B. Gleb And Pizza

本文介绍了一个计算几何问题,通过简单的模拟方法来确定哪些圆形香肠完全位于带有特定宽度边缘的大圆形比萨饼的边缘上。文章提供了一个C++实现示例。

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 (xi, yi).

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 xi, yi 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.

题目大意:一个分两层的大圆,给出一些小圆,求完全在大圆外层的小圆个数
题解报告:简单模拟,直接\(O(n)\)扫一边即可

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=1e5+5;
int x[N],y[N],r[N];int r1,d,n;
int js(int i){
    return x[i]*x[i]+y[i]*y[i];
}
bool check(int i){
    int dis=js(i);
    int t1=(r1-r[i])*(r1-r[i]),t2=(r[i]+r1-d)*(r[i]+r1-d);
    if(dis>=t2 && dis<=t1)return true;
    return false;
}
void work()
{
    scanf("%d%d%d",&r1,&d,&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&x[i],&y[i],&r[i]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(check(i))ans++;
    }
    printf("%d\n",ans);
}

int main()
{
    work();
    return 0;
}

转载于:https://www.cnblogs.com/Yuzao/p/7451695.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值