zzu--2014年11月16日月潭赛 B称号
1229: Rational Resistance
Time Limit: 1 Sec Memory Limit: 128 MB id=1229" style="color:rgb(26,92,200); text-decoration:none">Submit
Submit: 8 Solved: 4
[
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:
- one resistor;
- an element and one resistor plugged in sequence;
- 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
Sample Output
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
题意:就是去找最少要多少个电阻能够达成功能。
思路:假设 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称号的更多相关文章
- zzu--2014年11月16日月潭赛 C称号
1230: Magnets Time Limit: 1 Sec Memory Limit: 128 MB Submit: 24 Solved: 13 [id=1230" style=&q ...
- 11月16日《奥威Power-BI基于SQL的存储过程及自定义SQL脚本制作报表》腾讯课堂开课啦
上周的课程<奥威Power-BI vs微软Power BI>带同学们全面认识了两个Power-BI的使用情况,同学们已经迫不及待想知道这周的学习内容了吧!这周的课程关键词—— ...
- 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 ...
- CSDN下载频道2014年11月4日本-5日常维护公告
尊敬的用户: CSDN于2005年推出了下载服务.经过数年的发展.下载频道的用户已经为无数用户提供了帮助,分享500万的技术资源. CSDN下载频道将于2014年11月4日23点至11月5日8点进行积 ...
- 2014年11月17~11月18日,杨学明老师《企业IT需求收集和实施》内训在湖南长沙某酒店成功举办!
2014年11月17至18日,受湖南某软件企业的邀请,杨学明老师<企业IT需求收集和实施>内训在某长沙某五星级酒店成功举办!来自全国各地的IT高管和企业负责人参加了此次培训.杨学明老师分别 ...
- 2014年5月16至24日,杨学明老师为深圳创维RGB事业部提供两天的《软件测试管理》内训服务!
2014年5月16日和24日,<在软件开发流程中构筑软件质量—软件测试管理>内训课程在深圳创维集团成功举办!来自创维研发.测试.生产等部门的管理人员和核心骨干等参加了此次培训,此次培训由研 ...
- 北京Uber优步司机奖励政策(11月16日~11月22日)
用户组:人民优步“关羽组”(适用于11月16日-11月22日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/ ...
- OpenShare新功能@2014年11月 [2014-11-30]
新功能@Nov,2014 各门户层次主页布局自由编辑:升级为实时保存,这样用户编辑门户主页时,就算忘了点击“保存布局信息”,也不会丢失已做的工作 全方位支持匿名访问,支持构造公网以及extranet网 ...
- 2014年10月16号--for语句实例
Console.WriteLine("一对小兔一个月之后长成大兔,再过一个月后生新的一对兔子,且两年之后有多少对兔子,就是三兔子幼兔,小兔,成兔"); Console.WriteL ...
随机推荐
- TraceView总结
一.TraceView简单介绍 TraceView是AndroidSDK里面自带的工具,用于对Android的应用程序以及Framework层的代码进行性能分析. TraceView是图形化的工具,终 ...
- 无限层级且乱序的树形结构数据的整理,利用HashMap降低遍历次数
我们在展示一个机构树的时候,经常会遇到这种一个问题,查询数据的时候,是从下往上查的,但展示数据的时候,又要从下往上展示. 这时候就要把查询到的数据进行整理从而得到我们想要的结构. 举个样例. ID P ...
- Swift - iOS应用的国际化与本地化
在Xcode中我们可以很方便的将APP适配各种本地化语言.苹果的框架已经帮我们把不同语言的数据分离开,包括图片,声音,视频,文档,用户界面文字(甚至代码中编写的用户界面文字),它们会被建立在同一个bu ...
- 熬之滴水成石:最想深入了解的内容--windows内核机制(15)
66--内存管理(4) 说说在windows中内存空间初始化的事,开始的开始通过处理器的分页机制,预先建立相应足够的页表以便页表来访问物理内存.预先建立的这个物理内存的是windows自己的加载程序, ...
- MapReduce整体架构分析
继前段时间分析Redis源代码一段时间之后.我即将開始接下来的一段技术学习的征程.研究的技术就是当前很火热的Hadoop,可是一个Hadoop生态圈是很庞大的.所以首先我的打算是挑选当中的一部分模块, ...
- 实现StatusBar的Flat风格
效果见右图,OfficeXP里就是这样的风格,其实实现很简单,不必专门在网上找别人控件. 把StatusBar的SimplePanel设为False,点击Panels添加StatusPanel,把所有 ...
- Hadoop--序列化
序列化: 对象的序列化用于将一个对象编码成字节流,以及从字节流中重新构建对象. 将一个对象编码成一个字节流称为序列化该对象. 序列化三种主要的用途: 1.作为一种持久化格式. 2.作为一种通信的数据格 ...
- Java基础:泛型及其擦除性、不可协变性
转载请注明出处:jiq•钦's technical Blog 1泛型语法: 泛型类: class ClassName<T>{} 泛型方法:public <T> void f(T ...
- 新秀操作和维护注意事项:Windows关于使用Xshell管理你的云主机
假设你PC它是linux系统.那么直接与终端ssh命令就可以了.假设Windows系统.使用它是必要的sshclient. PS:我双系统. 有时候,他们想使用Windows的. Windows上ss ...
- .Net 配置文件——继承ConfigurationSection实现自己定义处理类处理自己定义配置节点
除了使用继承IConfigurationSectionHandler的方法定义处理自己定义节点的类.还能够通过继承ConfigurationSection类实现相同效果. 首先说下.Net配置文件里一 ...