Codeforces Round #200 (Div. 1)A. Rational Resistance 数学
A. Rational Resistance
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/343/problem/A
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 Re equals 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
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Sample Input
199 200
Sample Output
200
HINT
题意
你有无数个1欧的电阻,要求你用并联和串联构成a/b欧的电阻
问你最少需要多少个电阻
题解:
首先结构肯定是串联加并联啦
a/b,整数部分由串联构成,分数部分由并联构成就好了
这样就可以不停的递归了其实
代码:
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std; int main()
{
long long a,b;
scanf("%lld%lld",&a,&b);
if(a<b)swap(a,b);
long long ans = ;
while(a&&b)
{
ans += a/b;
a%=b;
swap(a,b);
}
printf("%lld\n",ans);
}
Codeforces Round #200 (Div. 1)A. Rational Resistance 数学的更多相关文章
- Codeforces Round #200 (Div. 2) C. Rational Resistance
C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #200 (Div. 1 + Div. 2)
A. Magnets 模拟. B. Simple Molecules 设12.13.23边的条数,列出三个等式,解即可. C. Rational Resistance 题目每次扩展的电阻之一是1Ω的, ...
- Codeforces Round #200 (Div. 1)D. Water Tree dfs序
D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/ ...
- Codeforces Round #200 (Div. 1) C. Read Time 二分
C. Read Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/C ...
- Codeforces Round #200 (Div. 1) B. Alternating Current 栈
B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- Codeforces Round #200 (Div. 1) BCD
为了锻炼个人能力奋力div1 为了不做原题从200开始 B 两个电线缠在一起了 能不能抓住两头一扯就给扯分开 很明显当len为odd的时候无解 当len为偶数的时候 可以任选一段长度为even的相同字 ...
- Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)
D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)
思路: dfs序其实是很水的东西. 和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的 ...
- Codeforces Round #200 (Div. 2) E. Read Time(二分)
题目链接 这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘. 看了一下题解,完全不知怎么弄.用一个指针从pre,枚举m,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...
随机推荐
- Vim Vundle 插件管理器
/********************************************************************** * Vim Vundle 插件管理器 * 说明: * 话 ...
- Flask
#environ:一个包含所有HTTP请求信息的dict对象 #start_response:一个发送HTTP响应的函数 def application(environ, start_response ...
- 【转】Android底层库和程序
原文网址:http://blog.csdn.net/louiswangbing/article/details/6616202 Android底层库和程序 1. 本地实现的基本结构 Andro ...
- (一)学习MVC之制作验证码
制作验证码的方法在@洞庭夕照 看到的,原文链接:http://www.cnblogs.com/mzwhj/archive/2012/10/22/2720089.html 现自己利用该方法制作一个简单的 ...
- LA 6540 Fibonacci Tree
以前做过的题···重新做一遍之后怎么做怎么wa···后来GG了···第二天看不知道为啥A了···难道我失忆了? 题意:无向图,边有黑色和白色两种颜色,求是否存在一个生成树中白边的个数是斐波那契数. 解 ...
- 配置Git自动补全功能
Git装好后,默认是不会有按tab补全命令的功能的.可如下配置: 去git的源码中,找到contrib/completion/git-completion.bash 将git-completion.b ...
- Linux新手必看:浅谈如何学习linux
本文在Creative Commons许可证下发布 一.起步 首先,应该为自己创造一个学习linux的环境--在电脑上装一个linux或unix问题1:版本的选择 北美用redhat,欧洲用SuSE, ...
- MFC消息映射机制
1.MFC应用框架主要类之间的关系 MFC自动生成的框架中重要的类有:C-App.CMainFrame.C-Doc和C-View. 其他的类如CClassView.CFileView等都是在框架窗口( ...
- NOIP2011 观光公交
3.观光公交 (bus.cpp/c/pas) 风景迷人的小城 Y 市,拥有 n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特 意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第 ...
- matlab 函数说明--waitforbuttonpress
这个函数的名称取得不是太好,一眼看去,好像是等待按键的意思,但是实际上它等待的是按键或者鼠标事件,他的功能描述如下: 停止脚本的执行,直至当前活动的窗口上检测到了鼠标按下事件或者有效的键盘事件(有效是 ...