SPOJ 3899. Finding Fractions 连分数
连分数乱搞,我反正是一眼没看出结果
某巨巨把这题讲解的比较详细 : http://blog.csdn.net/gogdizzy/article/details/8727386
令k = [a/b] 然后对于a/b < p/q < c/d 就能得到 (a-bk)/b < (p-qk)/q < (c-dk)/d 即 a'/b < p'/q < c'/d ----------------------每项都是<1的
因为显然 a/b < 1 这时如果c/d>1,那么最终结果p = q = 1 也显然的
如果c/d<=1,我们把原不等式倒数一下 ,只需要求 d/c < q/p < b/a 然后就能递归求解满足上式了
因为 d/c < q/p 所以 q > d*p/c 所以 q = q * d / c + 1
最后因为 p > q * a / b 所以 p = q * a / b + 1
LL dfs(LL a , LL b , LL c , LL d)
{
LL k = a/b;
a = a-b*k; c = c-d*k;
if(c > d) return ;
return d*dfs(d,c,b,a)/c+;
}
int main()
{
//freopen("in.txt","r",stdin);
LL a,b,c,d;
while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d))
{
LL q = dfs(a,b,c,d);
printf("%lld/%lld\n\n",a*q/b+,q);
}
return ;
}
SPOJ 3899. Finding Fractions 连分数的更多相关文章
- SPOJ3899——Finding Fractions
SPOJ上的每个题目都做得我泪牛满面. 这个题目也是的.题目意思是给你两个分数a/b和c/d,要你求出一个分数p/q,使得a/b<p/q<c/d,且p最小. 看完题目后半天都没有任何思路哦 ...
- 2014-2015 ACM-ICPC East Central North America Regional Contest (ECNA 2014) A、Continued Fractions 【模拟连分数】
任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 ...
- 每日英语:Why Are Fractions Key To Future Math Success?
Many students cruise along just fine in math until fourth grade or so. Then, they hit a wall -- frac ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- hdu-5992 Finding Hotels(kd-tree)
题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/ ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
随机推荐
- xcode 4 svn配置(host is unreachable)
xcode 4 svn配置 先保证你的xcode中已经安装了command line tools xcode -> preferences -> downloads -> comma ...
- android 聊天室窗体
public class MainActivity extends Activity { ScrollView scrollView; Button button; LinearLayout layo ...
- thinkphp5项目--企业单车网站(一)
thinkphp5项目--企业单车网站(一) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise Websitehttps:/ ...
- 23.IDEA 运行junit单元测试方法
转自:https://blog.csdn.net/weixin_42231507/article/details/80714716 配置Run,增加Junit 最终配置如下:
- C/C++(C++封装)
封装 当单一变量无法完成描述需求的时候,结构体类型解决了这一问题.可以将多个类型打包成一体,形成新的类型.这是 c 语言中封装的概念.但是,新类型并不包含,对数据类的操作.所的有操作都是通过函数的方式 ...
- vi命令常用操作
一.vi的操作模式 vi提供两种操作模式:输入模式(insert mode)和指令模式(command mode).在输入模式下,用户可输入文本资料.在指令模式下,可进行删除.修改等各种编辑动作. ...
- Django_模型操作
- [Python] isinstance() for checking object type
isinstance("foo", str) isinstance(1, int) isinstance(4.0, float)
- java中TCP传输协议
class TcpClient { public static void main(String[] args) throws Exception { //创建client的socket服务,指定目的 ...
- Codeforces 474D Flowers (线性dp 找规律)
D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...