HDU 3756 Dome of Circus
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3756
三分,求包括所有给出点的最小圆锥的高和半径.说实话这道题还不怎么理解.
自己一直WA,主要是搜索时cal与三分的条件没写对.参考别人的代码A了.还得回来看.
#include <iostream> #include <cmath> using namespace std; struct point { double x; double y; }p[10005]; int n; double cal(double h) { double R=0; for(int i=0;i<n;i++) { //R=max(R,h*p[i].x/(h-p[i].y)); if(R*(h-p[i].y)<h*p[i].x) R=h*p[i].x/(h-p[i].y); } return R; } double binary_search(double left,double right) { double mid ,midmid,R1,R2; while(fabs(right-left)>1e-8) { mid = (left+right)/2; midmid = (mid + right)/2; R1 = cal(mid); R2 = cal(midmid); if(mid*R1*R1>midmid*R2*R2) { left= mid; }else { right = midmid; } } return mid; } int main(int argc, const char *argv[]) { int T; scanf("%d",&T); while(T--) { scanf("%d",&n); double h = 0 , r = 0 ,Y; for(int i=0;i<n;i++) { double x,y,z; scanf("%lf%lf%lf",&x,&y,&p[i].y); p[i].x = sqrt(x*x +y*y); Y=max(p[i].y,Y); } r = binary_search(Y,1<<30); printf("%.3lf %.3lf\n",r,cal(r)); } return 0; }