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.
. 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.
. Determine the smallest possible number of resistors he needs to make such an element.
Input
 is irreducible. It is guaranteed that a solution always exists.
 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 %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,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ... 
随机推荐
- centos 搭建 darwin calendar 服务器
			方法一(官网方法): useradd caluser ----为日历服务器建立一个新用户,方便管理 passwd caluser -----新用户更改密码 su caluser mkdir ~/Cal ... 
- poj3686The Windy's (KM)
			http://poj.org/problem?id=3686 拆点很巧妙 将每个M个点拆成m*n个点 分别表示第i个玩具在第j个机器上倒数第K个处理 假设这k个玩具真正用在加工的时间分为a1,a2,a ... 
- bzoj1029
			贪心,比较明显了(很像USACO的风格); 按时间限制排序(升序) 顺次处理,如果当前时间能够修复就修复 否则就在之前修复的任务中找一个耗时最多(大于当前任务)的,改成修当前任务; 显然这样最优吧, ... 
- C#调用Geocoding API进行地理编码与逆编码
			使用C#调用Geocoding API来将地址转为经纬度,或者将经纬度转变为具体的地址. Geocoding API的详细介绍参见:http://developer.baidu.com/map/web ... 
- UVa 10214 (莫比乌斯反演 or 欧拉函数) Trees in a Wood.
			题意: 这道题和POJ 3090很相似,求|x|≤a,|y|≤b 中站在原点可见的整点的个数K,所有的整点个数为N(除去原点),求K/N 分析: 坐标轴上有四个可见的点,因为每个象限可见的点数都是一样 ... 
- 编写高效的C程序与C代码优化 via jobbole
			http://blog.jobbole.com/82582/ 原文出处: codeproject 译文出处:CodingWu的博客 欢迎分享原创到伯乐头条 
- oracle 问题若干 提醒注意
			1.Powerdesigner 里生成sql,在oracle中运行时报错:ORA-00907: 缺失右括号 解决:这样的问题很多时候是因为用了不正确的数据类型造成的.比如写作nvarchar(n),但 ... 
- 理解Android的手势识别
			对于触摸屏,其原生的消息无非按下.抬起.移动这几种,我们只需要简单重载onTouch或者设置触摸侦听器setOnTouchListener即可进行处理.不过,为了提高我们的APP的用户体验,有时候我们 ... 
- CF 55D - Beautiful numbers(数位DP)
			题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ... 
- selenium Grid
			Selenium Grid 的机制是启动一个 hub,然后启动多个 Selenium RC 注册到 hub 上, 当测试请求到 hub 时,hub 会将测试分发给 Selenium RC, Selen ... 
