zzu--2014年11月16日月潭赛 B称号

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;
}

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

时间: 2024-08-03 11:20:57

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

2014年11月16日:敏捷个人头手心活动报道

敏捷个人从2009年至今,经过不断的实践和总结,不断丰富并精炼,形成了一套高效的知行合一的个人体系化成长方法,并已经帮助数千人开启意识层面,并走上实践旅程,去找到真正的自己.为了让更多人了解和学习敏捷个人最新内容,决定再次开启敏捷个人北京俱乐部线下主题活动. 本次活动是敏捷个人头手心系列第一堂课北京线下分享,也是今年下半年唯一一次线下分享,内容有两部分: 敏捷个人头手心模型 如何成为一个专家 [签到] 第一个到场的敏友将获得快乐个人练习101张卡片一套,所以有敏友提前1个小时就到了.现场还准备了

(随笔)js获取当前时间并格格式化当前日期 获取date天后的日期(2014年11月27日 16:31:49)

(随笔)js获取当前时间并格格式化当前日期 获取date天后的日期参考网络(2014年11月27日 16:31:49 浙江) // 格式化当前日期 获取date天后的日期    function getNowFormatDate(date) {        var day = new Date();        var Year = 0;        var Month = 0;        var Day = 0;        var CurrentDate = "";  

2014年11月2日-11月9日 周总结

不敢相信一周的时间就这样过去了,只是简单的做了一个梦.醒来又是就是下周了. 周一周二所有的时间都是在准备地球制图的项目,周三编制制图报告.周四周五又都是在复习,准备地学信息分析与处理考试,一直都没有读书.一直到了周五晚上才有空读书.ArcGIS产品的白皮书,ENVI的产品白皮书和EV-Globe产品白皮书,粗略的浏览了一遍.又浏览了一下Matlab的帮助程序,收获很大,不过还是为了考试.值得高兴的是,计算机制图不需要考试,只需要交作品就好. 2014年11月10日-11月16日需要的事,AE二次

2014年11月12~11月14日,杨学明老师《软件测试管理》内训在北京某银行软件中心成功举办!

2014年11月12~11月14日,北京天气呈现少有的APEC蓝,著名研发管理专家杨学明老师为某银行提供了三天的内训服务,此次培训由两部分组成,第一部分是<软件测试管理高级实务>.第二部分是<软件测试需求分析和测试设计>,三天的培训非常紧张,包括老师讲解,案例演练,专题研讨,过程衔接非常紧密,课堂气氛也比较轻松,来自该银行核心系统和网银两个事业部的同事参加了此次培训,包括开发,需求,测试和维护人员等,课程结束后,举行了考试,大家对三天的学习进行回顾和总结,并准备把这两天学习到知识结

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

2014年11月17至18日,受湖南某软件企业的邀请,杨学明老师<企业IT需求收集和实施>内训在某长沙某五星级酒店成功举办!来自全国各地的IT高管和企业负责人参加了此次培训.杨学明老师分别从企业IT规划与选型普遍面临的问题和挑战. IT需求及策略. IT建设原则.IT流程体系. IT组织.IT选型步骤.IT实施步骤.实际选型和案例.选型流程分享等进行了讲解,共60多人参加了此次内训,课后大家一致认为课程含金量高,是国内最好的IT规划类课程.

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

2014年5月16日和24日,<在软件开发流程中构筑软件质量—软件测试管理>内训课程在深圳创维集团成功举办!来自创维研发.测试.生产等部门的管理人员和核心骨干等参加了此次培训,此次培训由研发管理资深顾问.产品测试专家杨学明先生主讲,本次课程采用全程案例分析讲解,让学员从一开始就融入到软件测试的场景中去,根据测试中所遇问题进行针对性讲解和讨论:课堂上许多企业都提出了很多高难度和有挑战性的问题,杨老师耐心地为各企业学员进行解答,很多学员代表表示对解决方案非常满意;此次课程课后综合满意度为87.4分

周浩晖 - 邪恶催眠师1(2014年11月1日)

<邪恶催眠师1> 作 者:周浩晖译 者:系 列:出 版:同心出版社字 数:298千字阅读完成:2014年11月1日

周浩晖 - 邪恶催眠师2(2014年11月7日)

<邪恶催眠师2> 作 者:周浩晖译 者:系 列:出 版:海峡书局字 数:289千字阅读完成:2014年11月7日

【每日圣经日历】2014年10月16日

注:移动用户(特别是苹果(Ipad))可以全选文字使用机器朗读 Jeudi le 16 Octobre 2014 礼拜四 2014年10月16日 Ceux qui avaient pour demeure les ténèbres et l'ombre de la mort Vivaient captifs dans la misère et dans les chanes, Parce qu'ils s'étaient révoltés contre les paroles de Dieu,