大圆套小圆,针对每个圆,找出包含它的那个面积最小的圆就行了,一共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
//
//
//