[hdu] 6097 "优秀的黄金分割三分"
来源:互联网 发布:出口退税算法 编辑:程序博客网 时间:2024/06/05 08:39
题解写了这句话,比赛时写了三分。T 到飞起。赛后发现三分写丑了。然后,还是需要快速读入。果然我还是菜呀、
#include"bits/stdc++.h"using namespace std;const double Pi = acos(-1.0);double x1, y1, x2, y2;double rr;typedef long long LL;struct FastIO{ static const int S = 2 * 100; int wpos; char wbuf[S]; FastIO() : wpos(0) {} inline int xchar() { static char buf[S]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, S, stdin); if (pos == len) exit(0); return buf[pos ++]; } inline int xuint() { int c = xchar(), x = 0; while (c <= 32) c = xchar(); for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0'; return x; } inline int xint() { int s = 1, c = xchar(), x = 0; while (c <= 32) c = xchar(); if (c == '-') s = -1, c = xchar(); for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0'; return x * s; } inline void xstring(char *s) { int c = xchar(); while (c <= 32) c = xchar(); for (; c > 32; c = xchar()) * s++ = c; *s = 0; } inline void wchar(int x) { if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0; wbuf[wpos ++] = x; } inline void wint(LL x) { if (x < 0) wchar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n ++] = '0' + x % 10, x /= 10; while (n--) wchar(s[n]); } inline void wstring(const char *s) { while (*s) wchar(*s++); } ~FastIO() { if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0; }} io;double get_lens(double arg1){ double x11 = rr * cos(arg1); double y12 = rr * sin(arg1); return sqrt((x11 - x1) * (x11 - x1) + (y12 - y1) * (y12 - y1)) + sqrt((x11 - x2) * (x11 - x2) + (y12 - y2) * (y12 - y2));}int main(){ //freopen("data.in", "r", stdin); //freopen("data1.out", "w", stdout); int T; double d = (sqrt(5) - 1) / 2; T = io.xint(); while(T --){ rr = io.xint(); x1 = io.xint(); y1 = io.xint(); x2 = io.xint(); y2 = io.xint(); double t = x1 * x1 + y1 * y1; double a = atan2(y1, x1); double b = atan2(y2, x2); if(a < 0) a += 2 * Pi; if(b < 0) b += 2 * Pi; double l, r; if(a > b){ r = a; l = b; } else{ r = b; l = a; } if(r - l > Pi){ r -= 2 * Pi; swap(l , r); } r = (l + r) / 2.0; double midl = (l * d + r * (1 - d)); double midr = (l * (1 - d) + r * d); double lans = get_lens(midl); double rans = get_lens(midr); for(int i = 1; i <= 30; i ++){ if(lans < rans){ r = midr; midr = midl; midl = l * d + r * (1 - d); rans = lans; lans = get_lens(midl); } else{ l = midl; midl = midr; midr = l * (1 - d) + r * d; lans = rans; rans = get_lens(midr); } } printf("%.12f\n", get_lens(l)); } return 0;}
阅读全文
0 0
- [hdu] 6097 "优秀的黄金分割三分"
- hdu 3400 悲剧的三分
- hdu-3400 有质量的三分题
- hdu 3400-三分套三分
- 黄金分割的哲学
- 黄金分割的哲学
- 神奇的黄金分割
- 黄金分割点的思考
- 黄金分割比的研究
- 无处不在的黄金分割比
- 黄金分割
- 黄金分割
- 黄金分割
- SGU 114 三分 类似于 HDU 4355(4355 同样也是一个三分的题目)
- 【三分】hdu 3400
- HDU 2899 三分查找
- HDU 2438 三分
- HDU 3400 两次三分
- 1717 好数
- Kafka温故而知新之环境搭建
- 将对象解析成json字符串
- text-overflow 文本超出显示...
- idea使用mybatis-plugins,出现Mybatis Plugin: Mybatis Plugin is not activated yet. Click here to enter you
- [hdu] 6097 "优秀的黄金分割三分"
- 数据结构实验之数组三:快速转置
- C.Primer.Plus(第六版)第16章 编程练习
- chown修改用户组所属
- 使用Spring Boot搭配mybatis配置项目
- HtmlAgilityPack
- JAVA多线程技术(基础篇)——多线程技能
- [转载]必看:数据平台的搭建教程及软件工具
- idea快捷键-总结