Dome of Circus POJ
来源:互联网 发布:麒麟啤酒 中国 知乎 编辑:程序博客网 时间:2024/05/18 10:48
题目链接: 点击打开
题意: 给定你一些点,让你找到包含这些点的最小体积圆锥。
做法也是很巧妙吧:
首先预处理数据: 把每个点变成二维坐标,分别表示x 轴,与 z 轴的距离。
利用三分
然后通过几何知识,得出满足的圆锥的高
得到最小体积的圆锥。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define INF 10000using namespace std;int n;struct Node{ double x,y,z,r;}node[10005];double solve(double r){ double mx=-1.0; for(int i=0;i<n;i++) { double cnt=node[i].z/(r-node[i].r); if(mx<cnt) mx=cnt; } return r*mx;}int main(){ while(scanf("%d",&n)!=EOF) { int mx=-1; for(int i=0;i<n;i++) { scanf("%lf%lf%lf",&node[i].x,&node[i].y,&node[i].z); node[i].r=sqrt(node[i].x*node[i].x+node[i].y*node[i].y); if(mx<node[i].r) mx=node[i].r; } double r=INF,l=mx; while(r-l>=0.00000001) { double mid=(r+l)/2; double midd=(r+mid)/2; double h1=solve(mid); double h2=solve(midd); if(h1*mid*mid> h2*midd*midd) l=mid; else r=midd; } printf("%.3f %.3f\n",solve(l),l); } return 0;}
三分与二分的区别: 二分法适用于单调函数,三分法常用于 单峰函数的最值。
模板就不需要了,理解一下就行。
阅读全文
0 0
- Dome of Circus POJ
- HDU Dome of Circus
- LA4986 Dome of Circus
- UVA1473 - Dome of Circus
- HDU 3756 Dome of Circus
- uva 1473 - Dome of Circus
- 【三分】HDU3756 Dome of Circus
- Dome of Circus(三分)
- hdu3756 Dome of Circus:三分学习
- HDU 3756 Dome of Circus 三分
- hdoj 3756 Dome of Circus(三分)
- hdu 3756 三分 Dome of Circus
- hdu 3756 Dome of Circus 三分
- UVa 1473 Dome of Circus(求凸包)
- hdu 3756 Dome of Circus 三分
- uva 1473 - Dome of Circus (几何 + 二分)
- HDU 3756 Dome of Circus 三分
- HDU 3756 Dome of Circus (三分)
- js 代码生成器
- iOS __attribute__ 总结
- nyoj--814--又见拦截导弹
- 网络协议篇之SNMP协议(三)—— 不同版本(SNMPv1、v2c、v3)报文区别
- 编程规范
- Dome of Circus POJ
- hdu6112 今夕何夕
- 多线程的代价
- Linux 日志文件
- 极验验证码破解
- DFS之P2089 烤鸡
- Java.Swing
- 字符串分割—String.split(String regex)用法
- HDU-6113 度度熊的01世界