输入两个数a, b 通过串联或并联单位电阻使电阻成为a / b,输出最小电阻数。
要注意题目给的两个公式,R0是单位电阻,Re是你计算出来的电阻。先判断输入的是否大于1,若大于则转换成小于1的分数,然后一
步一步减小分母,而后交换分子分母,直到分母或分子为1,因为为1的时候才可以直接加。
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
typedef long long ll;
ll a, b;
int main(int argc, char const *argv[])
{
cin >> a >> b;
if(a == b) {
cout << 1 << endl;
return 0;
}
ll ans = (ll)(a / b), cur = 0;
a -= ans * b;
while(true) {
if(a == 1) {
ans += b;
break;
}
if(b == 1) {
ans += a;
break;
}
cur += (ll)(b / a);
b %= a;
swap(a, b);
}
cout << ans + cur << endl;
return 0;
}

本博客介绍了一种使用单位电阻通过串联和并联的方式构造特定电阻值的算法,详细解释了如何通过逐步减小分母来实现目标电阻,并提供了一个AC代码示例,演示了解决过程。

.
In this case
.
Determine the smallest possible number of resistors he needs to make such an element.
.
We cannot make this element using two resistors.
255

被折叠的 条评论
为什么被折叠?



