UVALive-7509-Dome and Steles
来源:互联网 发布:看看电视软件 编辑:程序博客网 时间:2024/05/29 18:36
ACM模版
描述
题解
找到一篇不错的题解,写的十分详细,三分。
twh233’s blog,有详细的图解,我就不转述了。毕竟,懒。
代码
#include <iostream>#include <algorithm>#include <cmath>using namespace std;const int MAXN = 1e5 + 10;const double EPS = 1e-14;template <class T>inline void scan_d(T &ret){ char c; ret = 0; while ((c = getchar()) < '0' || c > '9'); while (c >= '0' && c <= '9') { ret = ret * 10 + (c - '0'), c = getchar(); }}int n;double w[MAXN];double calc(double x){ double x1 = x, x2 = 1 - x; if (x1 > x2) { swap(x1, x2); } double ans = w[n] + x2 * x2; for (int i = 1; i < n; i++) { if (i & 1) { x1++; ans = max(ans, w[n - i] + x1 * x1); } else { x2++; ans = max(ans, w[n - i] + x2 * x2); } } return sqrt(ans);}int main(){ int T; scan_d(T); for (int ce = 1; ce <= T; ce++) { printf("Case #%d: ", ce); scan_d(n); double a, b; for (int i = 1; i <= n; i++) { scanf("%lf%lf", &a, &b); if (a > b) { swap(a, b); } w[i] = a * a + (b / 2) * (b / 2); } sort(w + 1, w + n + 1); double l = 0, r = 1; while (l < r) { double m = (l + r) / 2; double _m = (m + r) / 2; if (calc(_m) < calc(m)) { l = m + EPS; } else { r = _m - EPS; } } printf("%.10f\n", calc(l)); } return 0;}
阅读全文
1 0
- UVALive-7509-Dome and Steles
- Dome of Tuxville [UVALive 3347] 模拟退火
- dome
- Boxes and Balls UVALive
- Boxes and Balls UVALive
- UVALive 4986 Dome of Circus(三分、凸包、凸性函数)
- UVALive 7500 Boxes and Balls
- UVALive 5031 Graph and Queries
- UVALive-7500-Boxes and Balls
- UVALive 3882 And Then There Was One
- UVALive 3882 And Then There Was One
- 字符->UVALive 4773 YY and YY Again
- UVALive - 5088 Alice and Bob's Trip
- UVALive 5968 Blade and Sword(搜索)
- Islands and Bridges -- UVAlive 3267(状压DP)
- UVALive 5031 Graph and Queries(离线,treap)
- UVALive 6918And Or(位运算)
- UVALive 5181 Stamps and Envelope Size
- 即时通讯
- tensorflow安装
- mac OSx 打包成dmg文件
- homestead安装php redis扩展 教程
- 几款开发 CSS 最好的前端开发工具
- UVALive-7509-Dome and Steles
- QFileInfo的各种文件名的区别
- 洛谷11月月赛 T3 斐波那契数列
- springmvc参数传递的几种乱码情况
- 大数据可视化之Nginx服务器日志分析及可视化展示(Nginx+flume+HDFS+Spark+Highcharts)
- 习题7.4
- 用过花呗、借呗及在校生必须全款买房?南京楼盘出最严规定。
- vs设置调试符号pdb
- [bzoj1057][dp]棋盘制作