1229: Rational Resistance

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 8  Solved: 4

[

id=1229" style="color:rgb(26,92,200); text-decoration:none">Submit][Status][Web
Board
]

Description

Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.

However, all Mike has is lots of identical resistors with unit resistance R0 = 1.
Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:

  1. one resistor;
  2. an element and one resistor plugged in sequence;
  3. an element and one resistor plugged in parallel.

With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals .
In this case Reequals the resistance of the element being connected.

Mike needs to assemble an element with a resistance equal to the fraction .
Determine the smallest possible number of resistors he needs to make such an element.

Input

The single input line contains two space-separated integers a and b
(1 <= a, b <= 1^18). It is guaranteed that the fraction  is
irreducible. It is guaranteed that a solution always exists.

Output

Print a single number — the answer to the problem.

Please do not use the %I64d specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams
or the%lld specifier.

Sample Input

1 13 2199 200

Sample Output

13200

HINT

In the first sample, one resistor is enough.

In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance .
We cannot make this element using two resistors.

Source

CF

题意:就是去找最少要多少个电阻能够达成功能。



思路:假设  a/b > 1 则 a/b 整数部分能够加到ans。a再模b。  假设a == b 则ans +=   a   ,  a变为0;  假设 a/b < 1 则b/a 整数部分能够加到ans。b再模a



比如:3/5  要先变为1 / ( 2 / 3 +1 )  ,ans=1。然后变为 1 / ( 1 / 2 + 1 ) 。 ans=2,最后1 /(1 + 1),ans =4



AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std; int main()
{
ll a, b;
while(scanf("%lld %lld", &a, &b)!=EOF)
{
ll ans = 0;
while(a)
{
if(a > b)
{
ll t = a / b;
ans+=t;
a=a%b;
}
else if(a == b)
{
ans+=a;
a=0;
}
else if(a < b)
{
ll t = b / a;
ans+=t;
t = b;
b = a;
a=t%a;
}
}
printf("%lld\n", ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

zzu--2014年11月16日月潭赛 B称号的更多相关文章

  1. zzu--2014年11月16日月潭赛 C称号

    1230: Magnets Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 24  Solved: 13 [id=1230" style=&q ...

  2. 11月16日《奥威Power-BI基于SQL的存储过程及自定义SQL脚本制作报表》腾讯课堂开课啦

           上周的课程<奥威Power-BI vs微软Power BI>带同学们全面认识了两个Power-BI的使用情况,同学们已经迫不及待想知道这周的学习内容了吧!这周的课程关键词—— ...

  3. 2016年11月16日 星期三 --出埃及记 Exodus 20:7

    2016年11月16日 星期三 --出埃及记 Exodus 20:7 "You shall not misuse the name of the LORD your God, for the ...

  4. CSDN下载频道2014年11月4日本-5日常维护公告

    尊敬的用户: CSDN于2005年推出了下载服务.经过数年的发展.下载频道的用户已经为无数用户提供了帮助,分享500万的技术资源. CSDN下载频道将于2014年11月4日23点至11月5日8点进行积 ...

  5. 2014年11月17~11月18日,杨学明老师《企业IT需求收集和实施》内训在湖南长沙某酒店成功举办!

    2014年11月17至18日,受湖南某软件企业的邀请,杨学明老师<企业IT需求收集和实施>内训在某长沙某五星级酒店成功举办!来自全国各地的IT高管和企业负责人参加了此次培训.杨学明老师分别 ...

  6. 2014年5月16至24日,杨学明老师为深圳创维RGB事业部提供两天的《软件测试管理》内训服务!

    2014年5月16日和24日,<在软件开发流程中构筑软件质量—软件测试管理>内训课程在深圳创维集团成功举办!来自创维研发.测试.生产等部门的管理人员和核心骨干等参加了此次培训,此次培训由研 ...

  7. 北京Uber优步司机奖励政策(11月16日~11月22日)

    用户组:人民优步“关羽组”(适用于11月16日-11月22日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/ ...

  8. OpenShare新功能@2014年11月 [2014-11-30]

    新功能@Nov,2014 各门户层次主页布局自由编辑:升级为实时保存,这样用户编辑门户主页时,就算忘了点击“保存布局信息”,也不会丢失已做的工作 全方位支持匿名访问,支持构造公网以及extranet网 ...

  9. 2014年10月16号--for语句实例

    Console.WriteLine("一对小兔一个月之后长成大兔,再过一个月后生新的一对兔子,且两年之后有多少对兔子,就是三兔子幼兔,小兔,成兔"); Console.WriteL ...

随机推荐

  1. RS100项目进展更新

    1. 添加手机界面访问网页,毕竟PDA的屏幕大小和PC机大小不一致,完成了一自适应网页,便于在手机上观看实时画面: 2. 此项目为一个远程视频监控+远程开关项目,远程PC机或者手机能操作到监控端的开关 ...

  2. js正则验证手机号码有效性

    验证130-139,150-159,180-189号码段的手机号码 <script type="text/javascript"> [-]{})|([-]{})|([- ...

  3. CentOS 6.4 x86_64 安装GCC 4.7.3

    下载gcc-4.7.3.tar.gz, 解压缩 wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.3/gcc-4.7.3.tar.gz tar -xzvf gcc-4.7. ...

  4. Kendo UI开发教程(22): Kendo MVVM 数据绑定(十一) Value

    Value绑定可以把ViewModel的某个属性绑定到DOM元素或某个UI组件的Value属性.当用户修改DOM元素或UI组件的值时,绑定的ViewModel的值也随之发生改名.同样,如果ViewMo ...

  5. Js版游戏打砖块开发过程详细

    最近对js的小游戏开发来了兴趣,前段时间由于回答度娘知道的提问写了个贪吃蛇,虽然难度不大并不复杂,感觉还挺有意思.感觉小时候玩过的什么俄罗斯方块,坦克大战什么的都可以试着用js实现下,这天来了兴致又想 ...

  6. [置顶] location.href你真的会用了?

    *.location.href 用法: top.location.href=”url”          在顶层页面打开url(跳出框架) self.location.href=”url”       ...

  7. 基于Hadoop技术实现的离线电商分析平台(Flume、Hadoop、Hbase、SpringMVC、highcharts)

    离线数据分析平台是一种利用hadoop集群开发工具的一种方式,主要作用是帮助公司对网站的应用有一个比较好的了解.尤其是在电商.旅游.银行.证券.游戏等领域有非常广泛,因为这些领域对数据和用户的特性把握 ...

  8. Oracle死锁、数据库链接问题

    --查询数据库锁表的信息 select do.object_name,t2.username,t2.sid,t2.serial#,t2.logon_time,t2.MACHINE,t2.state,t ...

  9. oracle触发器中增删改查本表

    oracle触发器中增删改查本表 (1)只有before insert触发器中才可以查询或更新本表 create or replace trigger tri_test_ins before inse ...

  10. 超炫的Button按钮展开弧形动画效果

    ----------------------收藏备用  ------------------------------- 代码下载:http://download.csdn.net/detail/qq2 ...