[HDU 6209] The Intersection
来源:互联网 发布:查看linux系统版本命令 编辑:程序博客网 时间:2024/06/07 18:27
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6209
题目大意:T组数据, 输入一个整数k,求最接近
思路:设
PS: 这个题要到处用long double
#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#define ld long doubleusing namespace std;const int lim = (int)1e5;int T, k;int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b);}void simplify(int &a, int &b){ int g = gcd(a, b); a /= g, b /= g;}int main(){ scanf("%d", &T); while (T --){ scanf("%d", &k); ld x = pow((ld)k, (ld)2.0 / 3); int a = (int)floor(x); int b = 1, c = a + 1, d = 1; if (1LL * a * a * a == 1LL * k * k){ printf("%d/1\n", a); continue; } int u, v; if (fabs((ld)a - x) < fabs((ld)c - x)) u = a, v = 1; else u = c, v = 1; while(1){ int i = a + c, j = b + d; simplify(i, j); if (j > lim) break; if (fabs((ld)1.0 * i / j - x) < fabs((ld)1.0 * u / v - x)) u = i, v = j; if ((ld)1.0 * i / j < x) a = i, b = j; else c = i, d = j; } printf("%d/%d\n", u, v); } return 0;}
阅读全文
0 0
- hdu 6209 The Intersection
- [HDU 6209] The Intersection
- HDU 6209 The Intersection(二分)
- 【2017青岛网络赛】1004 hdu 6209 The Intersection 二分
- Hdu 6209 The Intersection(Stern-Brocot tree+二分)
- Intersection HDU
- hdu 5120 Intersection
- hdu 5120 题解 Intersection
- hdu 5120 Intersection
- hdu 5120 Intersection
- hdu 5120 Intersection
- HDU 5120 Intersection
- HDU 5120 Intersection
- hdu 5120 Intersection
- HDU.5120 Intersection
- Intersection (hdu-5120)
- HDU —5120 Intersection
- HDU 4873ZCC Loves Intersection
- 数据库开发技术 课堂笔记4
- 关于sudo dpkg-divert --local --rename --add /sbin/initctl导致的开机无图标解决方法
- 简析fork和vfork区别以及进程和线程的区别和联系
- C++右值引用
- Struts2的架构和执行流程
- [HDU 6209] The Intersection
- mybatis environments
- Java实现——数组元素全排列
- python之numpy库学习常用函数(矩阵索引数据)
- BZOJ[3626][LNOI2014]LCA 树链剖分+线段树
- C语言二进制转十进制的技巧性方法
- 【数学建模】CUMCM-2013B 碎纸片的拼接复原 解题思路整理
- mybatis 引入映射器的方法
- mybantis 映射器的自动映射和驼峰映射