大圓套小圓,針對每個圓,找出包含它的那個面積最小的圓就行了,一共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//////