hiho 1611 气泡图 [Offer收割]编程练习赛32 Problem A 数学公式暴力

大圆套小圆,针对每个圆,找出包含它的那个面积最小的圆就行了,一共1000个,复杂度n方

这个题我还WA了两发。。。我还以为是EPS的问题,最后发现那个max值设的太小了,之前就写了一串9,后来改成比输入值的max大就过了。。。

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bits/stdc++.h>
using namespace std;

int N;

double X[1009];
double Y[1009];
double R[1009];

const double PI=acos(-1);

bool contain(double x1,double y1,double r1,double x2,double y2,double r2){
    if(r1-r2<=0.0000001)return false;
    double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    if(d+r2<=r1)return true;
    return false;
}



int main(){
    cin>>N;
    double maxR=0;
    for(int i=0;i<N;i++){
        scanf("%lf%lf%lf",&X[i],&Y[i],&R[i]);
        maxR=max(R[i],maxR);
    }
    double maxA=maxR*maxR*PI;
    for(int i=0;i<N;i++){
        int father=-1;
        double curArea=maxA+10;
        for(int j=0;j<N;j++){
            if(i==j)continue;
            if(contain(X[j],Y[j],R[j],X[i],Y[i],R[i])&&PI*R[j]*R[j]<curArea){
                curArea=PI*R[j]*R[j];
                father=j;
            }
        }
        if(father==-1)cout<<0<<endl;
        else cout<<father+1<<endl;
    }
    return 0;
}

//
//                       _oo0oo_
//                      o8888888o
//                      88" . "88
//                      (| -_- |)
//                      0\  =  /0
//                    ___/`---'\___
//                  .' \\|     |// '.
//                 / \\|||  :  |||// \
//                / _||||| -:- |||||- \
//               |   | \\\  -  /// |   |
//               | \_|  ''\---/''  |_/ |
//               \  .-\__  '-'  ___/-. /
//             ___'. .'  /--.--\  `. .'___
//          ."" '<  `.___\_<|>_/___.' >' "".
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//         \  \ `_.   \_ __\ /__ _/   .-` /  /
//     =====`-.____`.___ \_____/___.-`___.-'=====
//                       `=---='
//
//
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//               佛祖保佑         永无BUG
//
//
//


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值